#include <vcop/vcop.h>

typedef unsigned char uchar;

//#pragma DATA_SECTION(__pblock_vcop_sobelX_3x3_uchar_char, ".vcop_parameter_block")
//#pragma DATA_ALIGN(__pblock_vcop_sobelX_3x3_uchar_char, __ALIGNOF__(int));
unsigned short * __pblock_vcop_sobelX_3x3_uchar_char; //[32];

unsigned int vcop_sobelX_3x3_uchar_char_param_count(void)
{
   return 32u;
}

unsigned int vcop_sobelX_3x3_uchar_char_ctrl_count(void)
{
   return 0u;
}

unsigned int vcop_sobelX_3x3_uchar_char_init(
   __vptr_uint8 in,
   __vptr_int16 inter,
   __vptr_int8 out,
   int img_w,
   int img_h,
   int out_w,
   int out_h,
   int comp_w,
   int comp_h,
   int in_type,
   int inter_type,
   int out_type,
   int round_shift,
   unsigned short pblock[])
{
   int __offset = 0;
   /* Loop 1 PREGS */
   __vcop_pblock_init16(pblock, __offset+_PREG(2), 0);
   __vcop_pblock_init16(pblock, __offset+_PREG(3), 0);
   __vcop_pblock_init16(pblock, __offset+_PREG(4), (comp_h)-1u);
   __vcop_pblock_init16(pblock, __offset+_PREG(5), (comp_w/((8u) * 2))-1u);
   __vcop_pblock_init32(pblock, __offset+_PREG(6), (uchar *)inter);
   __vcop_pblock_init16(pblock, __offset+_PREG(8), 16);
   __vcop_pblock_init16(pblock, __offset+_PREG(9), (img_w*sizeof(*in)) -((8u*2)*sizeof(*in))*((comp_w/((8u) * 2))-1u));
   __vcop_pblock_init16(pblock, __offset+_PREG(10), 32);
   __vcop_pblock_init16(pblock, __offset+_PREG(11), (comp_w*sizeof(*inter)) -((8u*2)*sizeof(*inter))*((comp_w/((8u) * 2))-1u));
   __vcop_pblock_init32(pblock, __offset+_PREG(12), (uchar *)in);
   __vcop_pblock_init32(pblock, __offset+_PREG(14), (uchar *)in+2*sizeof(*in));
   __offset += 14;

   /* Loop 2 PREGS */
   const int preg_ref1 = _PREG(7);

   __vcop_pblock_init16(pblock, __offset+_PREG(2), 0);
   __vcop_pblock_init16(pblock, __offset+_PREG(3), 0);
   __vcop_pblock_init16(pblock, __offset+_PREG(4), (comp_h - 2)-1u);
   __vcop_pblock_init16(pblock, __offset+_PREG(5), (comp_w/(2 * (8u)))-1u);
   __vcop_pblock_init16(pblock, __offset+_PREG(6), __vcop_store_round_sat(SM_ASYMM,preg_ref1,RM_ROUND,3));
   __vcop_pblock_init16(pblock, __offset+_PREG(7), 127);
   __vcop_pblock_init32(pblock, __offset+_PREG(8), (uchar *)inter+2*comp_w*sizeof(*inter));
   __vcop_pblock_init32(pblock, __offset+_PREG(10), (uchar *)out);
   __vcop_pblock_init16(pblock, __offset+_PREG(12), 32);
   __vcop_pblock_init16(pblock, __offset+_PREG(13), (comp_w*sizeof(*inter)) -(2*8u*sizeof(*inter))*((comp_w/(2 * (8u)))-1u));
   __vcop_pblock_init16(pblock, __offset+_PREG(14), 16);
   __vcop_pblock_init16(pblock, __offset+_PREG(15), (out_w*sizeof(*out)) -(2*8u*sizeof(*out))*((comp_w/(2 * (8u)))-1u));
   __vcop_pblock_init32(pblock, __offset+_PREG(16), (uchar *)inter);
   __vcop_pblock_init32(pblock, __offset+_PREG(18), (uchar *)inter+comp_w*sizeof(*inter));
   __offset += 18;

   return 32u;
}

void vcop_sobelX_3x3_uchar_char_vloops(
   unsigned short pblock[])
{
   /* Kernel-wide Vector Registers */
   #pragma VCC_VREG("Vin", 16);
   #pragma VCC_VREG("Vin0", 17);
   #pragma VCC_VREG("Vin0_plus2", 18);
   #pragma VCC_VREG("Vin1", 19);
   #pragma VCC_VREG("Vin1_plus2", 20);
   #pragma VCC_VREG("Vin2", 21);
   #pragma VCC_VREG("Vin3", 22);
   #pragma VCC_VREG("Vin4", 23);
   #pragma VCC_VREG("Vin5", 24);
   #pragma VCC_VREG("Vout0", 25);
   #pragma VCC_VREG("Vout1", 26);
   #pragma VCC_VREG("Vsum0", 27);
   #pragma VCC_VREG("Vsum1", 28);

   __vcop_param(&pblock[0]);

   /* VLOOP 1 Start */

   /* VLOOP Local Vector Registers */
   

   /* VLOOP Local Address Generators */
   #pragma EVE_REG("inAddr", "A0");
   #pragma EVE_REG("outAddr", "A1");
   /* VLOOP Loop Control Variables   */
   #pragma EVE_REG("I1", "I3");
   #pragma EVE_REG("I2", "I4");
   

   __vcop_vloop(__vcop_compute(), 8u, 7u, 1u);
   __vcop_vagen(_AGEN(0), _PREG(8), _PREG(9), _PREG(0), _PREG(0));
   __vcop_vagen(_AGEN(1), _PREG(10), _PREG(11), _PREG(0), _PREG(0));
   __vcop_vload(__vcop_sizeBU(), __vcop_dintrlv(), _PREG(12), _AGEN(0), _VPAIR(17,19), __vcop_alws_condload());
   __vcop_vload(__vcop_sizeBU(), __vcop_dintrlv(), _PREG(14), _AGEN(0), _VPAIR(18,20), __vcop_alws_condload());
   __vcop_vsub(_VREG(17), _VREG(18), _VREG(27));
   __vcop_vsub(_VREG(19), _VREG(20), _VREG(28));
   __vcop_vstore(__vcop_unconditional(), __vcop_sizeH(), __vcop_intrlv(), __vcop_alws(), _VPAIR(27,28), _PREG(6), _AGEN(1), _PREG(0));
   __vcop_vloop_end(1u);

   /* VLOOP 2 Start */

   /* VLOOP Local Vector Registers */
   

   /* VLOOP Local Address Generators */
   #pragma EVE_REG("Addr0", "A0");
   #pragma EVE_REG("Addr1", "A1");
   /* VLOOP Loop Control Variables   */
   #pragma EVE_REG("I1", "I3");
   #pragma EVE_REG("I2", "I4");
   

   __vcop_vloop(__vcop_compute(), 11u, 9u, 2u);
   __vcop_vagen(_AGEN(0), _PREG(12), _PREG(13), _PREG(0), _PREG(0));
   __vcop_vagen(_AGEN(1), _PREG(14), _PREG(15), _PREG(0), _PREG(0));
   __vcop_vload(__vcop_sizeH(), __vcop_dintrlv(), _PREG(16), _AGEN(0), _VPAIR(17,19), __vcop_alws_condload());
   __vcop_vload(__vcop_sizeH(), __vcop_dintrlv(), _PREG(18), _AGEN(0), _VPAIR(21,22), __vcop_alws_condload());
   __vcop_vload(__vcop_sizeH(), __vcop_dintrlv(), _PREG(8), _AGEN(0), _VPAIR(23,24), __vcop_alws_condload());
   __vcop_vadd(_VREG(17), _VREG(21), _VREG(25));
   __vcop_vadd(_VREG(19), _VREG(22), _VREG(26));
   __vcop_vadd3(_VREG(21), _VREG(23), _VREG(25));
   __vcop_vadd3(_VREG(22), _VREG(24), _VREG(26));
   __vcop_vstore(__vcop_unconditional(), __vcop_sizeB(), __vcop_intrlv(), __vcop_alws(), _VPAIR(25,26), _PREG(10), _AGEN(1), _PREG(6));
   __vcop_vloop_end(2u);

}

void vcop_sobelX_3x3_uchar_char(
   __vptr_uint8 in,
   __vptr_int16 inter,
   __vptr_int8 out,
   int img_w,
   int img_h,
   int out_w,
   int out_h,
   int comp_w,
   int comp_h,
   int in_type,
   int inter_type,
   int out_type,
   int round_shift)
{
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
   vcop_sobelX_3x3_uchar_char_init(in, inter, out, img_w, img_h, out_w, out_h, comp_w, comp_h, in_type, inter_type, out_type, round_shift, __pblock_vcop_sobelX_3x3_uchar_char);

   VCOP_BUF_SWITCH_SET(WBUF_VCOP, IBUFHB_VCOP, IBUFLB_VCOP,
                   IBUFHA_VCOP, IBUFLA_VCOP);
   vcop_sobelX_3x3_uchar_char_vloops(__pblock_vcop_sobelX_3x3_uchar_char);

   _vcop_vloop_done();
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
}

void vcop_sobelX_3x3_uchar_char_custom(
   __vptr_uint8 in,
   __vptr_int16 inter,
   __vptr_int8 out,
   int img_w,
   int img_h,
   int out_w,
   int out_h,
   int comp_w,
   int comp_h,
   int in_type,
   int inter_type,
   int out_type,
   int round_shift,
   unsigned short pblock[])
{
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
   vcop_sobelX_3x3_uchar_char_init(in, inter, out, img_w, img_h, out_w, out_h, comp_w, comp_h, in_type, inter_type, out_type, round_shift, pblock);

   VCOP_BUF_SWITCH_SET(WBUF_VCOP, IBUFHB_VCOP, IBUFLB_VCOP,
                   IBUFHA_VCOP, IBUFLA_VCOP);
   vcop_sobelX_3x3_uchar_char_vloops(pblock);

   _vcop_vloop_done();
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
}
#if 0
//#pragma DATA_SECTION(__pblock_vcop_sobelX_3x3_2D_uchar_char, ".vcop_parameter_block")
//#pragma DATA_ALIGN(__pblock_vcop_sobelX_3x3_2D_uchar_char, __ALIGNOF__(int));
unsigned short * __pblock_vcop_sobelX_3x3_2D_uchar_char; //[24]

unsigned int vcop_sobelX_3x3_2D_uchar_char_param_count(void)
{
   return 24u;
}

unsigned int vcop_sobelX_3x3_2D_uchar_char_ctrl_count(void)
{
   return 0u;
}

unsigned int vcop_sobelX_3x3_2D_uchar_char_init(
   __vptr_uint8 in,
   __vptr_int8 coef,
   __vptr_int8 out,
   int img_w,
   int img_h,
   int out_w,
   int out_h,
   int comp_w,
   int comp_h,
   int in_type,
   int coef_type,
   int out_type,
   int round_shift,
   unsigned short pblock[])
{
   int __offset = 0;
   /* Loop 1 PREGS */
   const int preg_ref2 = _PREG(12);

   __vcop_pblock_init16(pblock, __offset+_PREG(2), (comp_h)-1u);
   __vcop_pblock_init16(pblock, __offset+_PREG(3), (comp_w/((8u) * 2))-1u);
   __vcop_pblock_init16(pblock, __offset+_PREG(4), (3)-1u);
   __vcop_pblock_init16(pblock, __offset+_PREG(5), (3 - 1)-1u);
   __vcop_pblock_init16(pblock, __offset+_PREG(6), __vcop_store_round_sat(SM_4PARAM,preg_ref2,RM_ROUND,round_shift));
   __vcop_pblock_init16(pblock, __offset+_PREG(7), 16);
   __vcop_pblock_init32(pblock, __offset+_PREG(8), (uchar *)coef);
   __vcop_pblock_init32(pblock, __offset+_PREG(10), (uchar *)out);
   __vcop_pblock_4param_init(pblock, __offset+_PREG(12), (255), (255), (0), (0));
   __vcop_pblock_init16(pblock, __offset+_PREG(16), (out_w*sizeof(*out)) -((8u*2)*sizeof(*out))*((comp_w/((8u) * 2))-1u));
   __vcop_pblock_init16(pblock, __offset+_PREG(17), 2);
   __vcop_pblock_init16(pblock, __offset+_PREG(18), -8);
   __vcop_pblock_init16(pblock, __offset+_PREG(19), (img_w*sizeof(*in)) -(2*sizeof(*in))*((3 - 1)-1u));
   __vcop_pblock_init16(pblock, __offset+_PREG(20), ((8u*2)*sizeof(*in)) -(img_w*sizeof(*in))*((3)-1u) -(2*sizeof(*in))*((3 - 1)-1u));
   __vcop_pblock_init16(pblock, __offset+_PREG(21), (img_w*sizeof(*in)) -((8u*2)*sizeof(*in))*((comp_w/((8u) * 2))-1u) -(img_w*sizeof(*in))*((3)-1u) -(2*sizeof(*in))*((3 - 1)-1u));
   __vcop_pblock_init32(pblock, __offset+_PREG(22), 0);
   __vcop_pblock_init32(pblock, __offset+_PREG(24), (uchar *)in);
   __offset += 24;

   return 24u;
}

void vcop_sobelX_3x3_2D_uchar_char_vloops(
   unsigned short pblock[])
{
   /* Kernel-wide Vector Registers */

   __vcop_param(&pblock[0]);

   /* VLOOP 1 Start */

   /* VLOOP Local Vector Registers */
   

   /* VLOOP Local Address Generators */
   #pragma EVE_REG("outAddr", "A0");
   #pragma EVE_REG("coefAddr", "A1");
   #pragma EVE_REG("dataAddr", "A2");
   /* VLOOP Loop Control Variables   */
   #pragma EVE_REG("I1", "I1");
   #pragma EVE_REG("I2", "I2");
   #pragma EVE_REG("I3", "I3");
   #pragma EVE_REG("I4", "I4");
   

   __vcop_vloop(__vcop_compute(), 11u, 12u, 1u);
   __vcop_vinit(__vcop_sizeW(), __vcop_i34_zero(), _PREG(22), _VREG(4));
   __vcop_vinit(__vcop_sizeW(), __vcop_i34_zero(), _PREG(22), _VREG(5));
   __vcop_vagen(_AGEN(0), _PREG(0), _PREG(0), _PREG(7), _PREG(16));
   __vcop_vagen(_AGEN(1), _PREG(17), _PREG(1), _PREG(18), _PREG(18));
   __vcop_vagen(_AGEN(2), _PREG(17), _PREG(19), _PREG(20), _PREG(21));
   __vcop_vload(__vcop_sizeBU(), __vcop_dintrlv(), _PREG(24), _AGEN(2), _VPAIR(0,1), __vcop_alws_condload());
   __vcop_vload(__vcop_sizeB(), __vcop_1pt(), _PREG(8), _AGEN(1), _VREG(2), __vcop_alws());
   __vcop_vmadd(_VREG(0), _VREG(2), _VREG(4), _PREG(0));
   __vcop_vmadd(_VREG(1), _VREG(2), _VREG(5), _PREG(0));
   __vcop_vstore(__vcop_unconditional(), __vcop_sizeB(), __vcop_intrlv(), __vcop_last_i34(), _VPAIR(4,5), _PREG(10), _AGEN(0), _PREG(6));
   __vcop_vloop_end(1u);

}

void vcop_sobelX_3x3_2D_uchar_char(
   __vptr_uint8 in,
   __vptr_int8 coef,
   __vptr_int8 out,
   int img_w,
   int img_h,
   int out_w,
   int out_h,
   int comp_w,
   int comp_h,
   int in_type,
   int coef_type,
   int out_type,
   int round_shift)
{
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
   vcop_sobelX_3x3_2D_uchar_char_init(in, coef, out, img_w, img_h, out_w, out_h, comp_w, comp_h, in_type, coef_type, out_type, round_shift, __pblock_vcop_sobelX_3x3_2D_uchar_char);

   VCOP_BUF_SWITCH_SET(WBUF_VCOP, IBUFHB_VCOP, IBUFLB_VCOP,
                   IBUFHA_VCOP, IBUFLA_VCOP);
   vcop_sobelX_3x3_2D_uchar_char_vloops(__pblock_vcop_sobelX_3x3_2D_uchar_char);

   _vcop_vloop_done();
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
}

void vcop_sobelX_3x3_2D_uchar_char_custom(
   __vptr_uint8 in,
   __vptr_int8 coef,
   __vptr_int8 out,
   int img_w,
   int img_h,
   int out_w,
   int out_h,
   int comp_w,
   int comp_h,
   int in_type,
   int coef_type,
   int out_type,
   int round_shift,
   unsigned short pblock[])
{
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
   vcop_sobelX_3x3_2D_uchar_char_init(in, coef, out, img_w, img_h, out_w, out_h, comp_w, comp_h, in_type, coef_type, out_type, round_shift, pblock);

   VCOP_BUF_SWITCH_SET(WBUF_VCOP, IBUFHB_VCOP, IBUFLB_VCOP,
                   IBUFHA_VCOP, IBUFLA_VCOP);
   vcop_sobelX_3x3_2D_uchar_char_vloops(pblock);

   _vcop_vloop_done();
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
}
#endif
//#pragma DATA_SECTION(__pblock_vcop_sobelY_3x3_uchar_char, ".vcop_parameter_block")
//#pragma DATA_ALIGN(__pblock_vcop_sobelY_3x3_uchar_char, __ALIGNOF__(int));
unsigned short * __pblock_vcop_sobelY_3x3_uchar_char; //[32];

unsigned int vcop_sobelY_3x3_uchar_char_param_count(void)
{
   return 32u;
}

unsigned int vcop_sobelY_3x3_uchar_char_ctrl_count(void)
{
   return 0u;
}

unsigned int vcop_sobelY_3x3_uchar_char_init(
   __vptr_uint8 in,
   __vptr_int16 inter,
   __vptr_int8 out,
   int img_w,
   int img_h,
   int out_w,
   int out_h,
   int comp_w,
   int comp_h,
   int in_type,
   int inter_type,
   int out_type,
   int round_shift,
   unsigned short pblock[])
{
   int __offset = 0;
   /* Loop 1 PREGS */
   __vcop_pblock_init16(pblock, __offset+_PREG(2), 0);
   __vcop_pblock_init16(pblock, __offset+_PREG(3), 0);
   __vcop_pblock_init16(pblock, __offset+_PREG(4), (comp_h)-1u);
   __vcop_pblock_init16(pblock, __offset+_PREG(5), (comp_w/(8u))-1u);
   __vcop_pblock_init32(pblock, __offset+_PREG(6), (uchar *)in+2*sizeof(*in));
   __vcop_pblock_init32(pblock, __offset+_PREG(8), (uchar *)inter);
   __vcop_pblock_init16(pblock, __offset+_PREG(10), 8);
   __vcop_pblock_init16(pblock, __offset+_PREG(11), (img_w*sizeof(*in)) -(8u*sizeof(*in))*((comp_w/(8u))-1u));
   __vcop_pblock_init16(pblock, __offset+_PREG(12), 16);
   __vcop_pblock_init16(pblock, __offset+_PREG(13), (comp_w*sizeof(*inter)) -(8u*sizeof(*inter))*((comp_w/(8u))-1u));
   __vcop_pblock_init32(pblock, __offset+_PREG(14), (uchar *)in);
   __vcop_pblock_init32(pblock, __offset+_PREG(16), (uchar *)in+sizeof(*in));
   __offset += 16;

   /* Loop 2 PREGS */
   const int preg_ref2 = _PREG(7);

   __vcop_pblock_init16(pblock, __offset+_PREG(2), 0);
   __vcop_pblock_init16(pblock, __offset+_PREG(3), 0);
   __vcop_pblock_init16(pblock, __offset+_PREG(4), (comp_h - 2)-1u);
   __vcop_pblock_init16(pblock, __offset+_PREG(5), (comp_w/(2 * (8u)))-1u);
   __vcop_pblock_init16(pblock, __offset+_PREG(6), __vcop_store_round_sat(SM_ASYMM,preg_ref2,RM_ROUND,3));
   __vcop_pblock_init16(pblock, __offset+_PREG(7), 127);
   __vcop_pblock_init32(pblock, __offset+_PREG(8), (uchar *)out);
   __vcop_pblock_init16(pblock, __offset+_PREG(10), 32);
   __vcop_pblock_init16(pblock, __offset+_PREG(11), (comp_w*sizeof(*inter)) -(2*8u*sizeof(*inter))*((comp_w/(2 * (8u)))-1u));
   __vcop_pblock_init16(pblock, __offset+_PREG(12), 16);
   __vcop_pblock_init16(pblock, __offset+_PREG(13), (out_w*sizeof(*out)) -(2*8u*sizeof(*out))*((comp_w/(2 * (8u)))-1u));
   __vcop_pblock_init32(pblock, __offset+_PREG(14), (uchar *)inter);
   __vcop_pblock_init32(pblock, __offset+_PREG(16), (uchar *)inter+2*comp_w*sizeof(*inter));
   __offset += 16;

   return 32u;
}

void vcop_sobelY_3x3_uchar_char_vloops(
   unsigned short pblock[])
{
   /* Kernel-wide Vector Registers */
   #pragma VCC_VREG("V_2", 16);
   #pragma VCC_VREG("Vctr", 17);
   #pragma VCC_VREG("Vin", 18);
   #pragma VCC_VREG("Vin0", 19);
   #pragma VCC_VREG("Vin1", 20);
   #pragma VCC_VREG("Vin2", 21);
   #pragma VCC_VREG("Vin3", 22);
   #pragma VCC_VREG("Vin_minus1", 23);
   #pragma VCC_VREG("Vin_minus2", 24);
   #pragma VCC_VREG("Vin_plus1", 25);
   #pragma VCC_VREG("Vin_plus2", 26);
   #pragma VCC_VREG("Vout0", 27);
   #pragma VCC_VREG("Vout1", 28);
   #pragma VCC_VREG("Vsum", 29);
   #pragma VCC_VREG("Vtmp", 30);
   #pragma VCC_VREG("Vtmp1", 31);
   #pragma VCC_VREG("Vtmp2", 32);

   __vcop_param(&pblock[0]);

   /* VLOOP 1 Start */

   /* VLOOP Local Vector Registers */
   

   /* VLOOP Local Address Generators */
   #pragma EVE_REG("inAddr", "A0");
   #pragma EVE_REG("outAddr", "A1");
   /* VLOOP Loop Control Variables   */
   #pragma EVE_REG("I1", "I3");
   #pragma EVE_REG("I2", "I4");
   

   __vcop_vloop(__vcop_compute(), 10u, 8u, 1u);
   __vcop_vagen(_AGEN(0), _PREG(10), _PREG(11), _PREG(0), _PREG(0));
   __vcop_vagen(_AGEN(1), _PREG(12), _PREG(13), _PREG(0), _PREG(0));
   __vcop_vload(__vcop_sizeBU(), __vcop_npt(), _PREG(14), _AGEN(0), _VREG(18), __vcop_alws_condload());
   __vcop_vload(__vcop_sizeBU(), __vcop_npt(), _PREG(16), _AGEN(0), _VREG(25), __vcop_alws_condload());
   __vcop_vload(__vcop_sizeBU(), __vcop_npt(), _PREG(6), _AGEN(0), _VREG(26), __vcop_alws_condload());
   __vcop_vadd(_VREG(18), _VREG(25), _VREG(31));
   __vcop_vadd(_VREG(25), _VREG(26), _VREG(32));
   __vcop_vadd(_VREG(31), _VREG(32), _VREG(29));
   __vcop_vstore(__vcop_unconditional(), __vcop_sizeH(), __vcop_npt(), __vcop_alws(), _VREG(29), _PREG(8), _AGEN(1), _PREG(0));
   __vcop_vloop_end(1u);

   /* VLOOP 2 Start */

   /* VLOOP Local Vector Registers */
   

   /* VLOOP Local Address Generators */
   #pragma EVE_REG("Addr0", "A0");
   #pragma EVE_REG("Addr1", "A1");
   /* VLOOP Loop Control Variables   */
   #pragma EVE_REG("I1", "I3");
   #pragma EVE_REG("I2", "I4");
   

   __vcop_vloop(__vcop_compute(), 8u, 8u, 2u);
   __vcop_vagen(_AGEN(0), _PREG(10), _PREG(11), _PREG(0), _PREG(0));
   __vcop_vagen(_AGEN(1), _PREG(12), _PREG(13), _PREG(0), _PREG(0));
   __vcop_vload(__vcop_sizeH(), __vcop_dintrlv(), _PREG(14), _AGEN(0), _VPAIR(19,20), __vcop_alws_condload());
   __vcop_vload(__vcop_sizeH(), __vcop_dintrlv(), _PREG(16), _AGEN(0), _VPAIR(21,22), __vcop_alws_condload());
   __vcop_vsub(_VREG(19), _VREG(21), _VREG(27));
   __vcop_vsub(_VREG(20), _VREG(22), _VREG(28));
   __vcop_vstore(__vcop_unconditional(), __vcop_sizeB(), __vcop_intrlv(), __vcop_alws(), _VPAIR(27,28), _PREG(8), _AGEN(1), _PREG(6));
   __vcop_vloop_end(2u);

}

void vcop_sobelY_3x3_uchar_char(
   __vptr_uint8 in,
   __vptr_int16 inter,
   __vptr_int8 out,
   int img_w,
   int img_h,
   int out_w,
   int out_h,
   int comp_w,
   int comp_h,
   int in_type,
   int inter_type,
   int out_type,
   int round_shift)
{
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
   vcop_sobelY_3x3_uchar_char_init(in, inter, out, img_w, img_h, out_w, out_h, comp_w, comp_h, in_type, inter_type, out_type, round_shift, __pblock_vcop_sobelY_3x3_uchar_char);

   VCOP_BUF_SWITCH_SET(WBUF_VCOP, IBUFHB_VCOP, IBUFLB_VCOP,
                   IBUFHA_VCOP, IBUFLA_VCOP);
   vcop_sobelY_3x3_uchar_char_vloops(__pblock_vcop_sobelY_3x3_uchar_char);

   _vcop_vloop_done();
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
}

void vcop_sobelY_3x3_uchar_char_custom(
   __vptr_uint8 in,
   __vptr_int16 inter,
   __vptr_int8 out,
   int img_w,
   int img_h,
   int out_w,
   int out_h,
   int comp_w,
   int comp_h,
   int in_type,
   int inter_type,
   int out_type,
   int round_shift,
   unsigned short pblock[])
{
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
   vcop_sobelY_3x3_uchar_char_init(in, inter, out, img_w, img_h, out_w, out_h, comp_w, comp_h, in_type, inter_type, out_type, round_shift, pblock);

   VCOP_BUF_SWITCH_SET(WBUF_VCOP, IBUFHB_VCOP, IBUFLB_VCOP,
                   IBUFHA_VCOP, IBUFLA_VCOP);
   vcop_sobelY_3x3_uchar_char_vloops(pblock);

   _vcop_vloop_done();
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
}
#if 0
//#pragma DATA_SECTION(__pblock_vcop_sobelY_3x3_2D_uchar_char, ".vcop_parameter_block")
//#pragma DATA_ALIGN(__pblock_vcop_sobelY_3x3_2D_uchar_char, __ALIGNOF__(int));
unsigned short * __pblock_vcop_sobelY_3x3_2D_uchar_char; //[24];

unsigned int vcop_sobelY_3x3_2D_uchar_char_param_count(void)
{
   return 24u;
}

unsigned int vcop_sobelY_3x3_2D_uchar_char_ctrl_count(void)
{
   return 0u;
}

unsigned int vcop_sobelY_3x3_2D_uchar_char_init(
   __vptr_uint8 in,
   __vptr_int8 coef,
   __vptr_int8 out,
   int img_w,
   int img_h,
   int out_w,
   int out_h,
   int comp_w,
   int comp_h,
   int in_type,
   int coef_type,
   int out_type,
   int round_shift,
   unsigned short pblock[])
{
   int __offset = 0;
   /* Loop 1 PREGS */
   const int preg_ref4 = _PREG(12);

   __vcop_pblock_init16(pblock, __offset+_PREG(2), (comp_h - 2)-1u);
   __vcop_pblock_init16(pblock, __offset+_PREG(3), (comp_w/((8u) * 2))-1u);
   __vcop_pblock_init16(pblock, __offset+_PREG(4), (3 - 1)-1u);
   __vcop_pblock_init16(pblock, __offset+_PREG(5), (3)-1u);
   __vcop_pblock_init16(pblock, __offset+_PREG(6), __vcop_store_round_sat(SM_4PARAM,preg_ref4,RM_ROUND,3));
   __vcop_pblock_init16(pblock, __offset+_PREG(7), 16);
   __vcop_pblock_init32(pblock, __offset+_PREG(8), (uchar *)coef);
   __vcop_pblock_init32(pblock, __offset+_PREG(10), (uchar *)out);
   __vcop_pblock_4param_init(pblock, __offset+_PREG(12), (255), (255), (0), (0));
   __vcop_pblock_init16(pblock, __offset+_PREG(16), (out_w*sizeof(*out)) -((8u*2)*sizeof(*out))*((comp_w/((8u) * 2))-1u));
   __vcop_pblock_init16(pblock, __offset+_PREG(17), 4);
   __vcop_pblock_init16(pblock, __offset+_PREG(18), -8);
   __vcop_pblock_init16(pblock, __offset+_PREG(19), (2*img_w*sizeof(*in)) -(sizeof(*in))*((3)-1u));
   __vcop_pblock_init16(pblock, __offset+_PREG(20), ((8u*2)*sizeof(*in)) -(2*img_w*sizeof(*in))*((3 - 1)-1u) -(sizeof(*in))*((3)-1u));
   __vcop_pblock_init16(pblock, __offset+_PREG(21), (img_w*sizeof(*in)) -((8u*2)*sizeof(*in))*((comp_w/((8u) * 2))-1u) -(2*img_w*sizeof(*in))*((3 - 1)-1u) -(sizeof(*in))*((3)-1u));
   __vcop_pblock_init32(pblock, __offset+_PREG(22), 0);
   __vcop_pblock_init32(pblock, __offset+_PREG(24), (uchar *)in);
   __offset += 24;

   return 24u;
}

void vcop_sobelY_3x3_2D_uchar_char_vloops(
   unsigned short pblock[])
{
   /* Kernel-wide Vector Registers */

   __vcop_param(&pblock[0]);

   /* VLOOP 1 Start */

   /* VLOOP Local Vector Registers */
   

   /* VLOOP Local Address Generators */
   #pragma EVE_REG("outAddr", "A0");
   #pragma EVE_REG("coefAddr", "A1");
   #pragma EVE_REG("dataAddr", "A2");
   /* VLOOP Loop Control Variables   */
   #pragma EVE_REG("I1", "I1");
   #pragma EVE_REG("I2", "I2");
   #pragma EVE_REG("I3", "I3");
   #pragma EVE_REG("I4", "I4");
   

   __vcop_vloop(__vcop_compute(), 11u, 12u, 1u);
   __vcop_vinit(__vcop_sizeW(), __vcop_i34_zero(), _PREG(22), _VREG(4));
   __vcop_vinit(__vcop_sizeW(), __vcop_i34_zero(), _PREG(22), _VREG(5));
   __vcop_vagen(_AGEN(0), _PREG(0), _PREG(0), _PREG(7), _PREG(16));
   __vcop_vagen(_AGEN(1), _PREG(1), _PREG(17), _PREG(18), _PREG(18));
   __vcop_vagen(_AGEN(2), _PREG(1), _PREG(19), _PREG(20), _PREG(21));
   __vcop_vload(__vcop_sizeBU(), __vcop_dintrlv(), _PREG(24), _AGEN(2), _VPAIR(0,1), __vcop_alws_condload());
   __vcop_vload(__vcop_sizeB(), __vcop_1pt(), _PREG(8), _AGEN(1), _VREG(2), __vcop_alws());
   __vcop_vmadd(_VREG(0), _VREG(2), _VREG(4), _PREG(0));
   __vcop_vmadd(_VREG(1), _VREG(2), _VREG(5), _PREG(0));
   __vcop_vstore(__vcop_unconditional(), __vcop_sizeB(), __vcop_intrlv(), __vcop_last_i34(), _VPAIR(4,5), _PREG(10), _AGEN(0), _PREG(6));
   __vcop_vloop_end(1u);

}

void vcop_sobelY_3x3_2D_uchar_char(
   __vptr_uint8 in,
   __vptr_int8 coef,
   __vptr_int8 out,
   int img_w,
   int img_h,
   int out_w,
   int out_h,
   int comp_w,
   int comp_h,
   int in_type,
   int coef_type,
   int out_type,
   int round_shift)
{
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
   vcop_sobelY_3x3_2D_uchar_char_init(in, coef, out, img_w, img_h, out_w, out_h, comp_w, comp_h, in_type, coef_type, out_type, round_shift, __pblock_vcop_sobelY_3x3_2D_uchar_char);

   VCOP_BUF_SWITCH_SET(WBUF_VCOP, IBUFHB_VCOP, IBUFLB_VCOP,
                   IBUFHA_VCOP, IBUFLA_VCOP);
   vcop_sobelY_3x3_2D_uchar_char_vloops(__pblock_vcop_sobelY_3x3_2D_uchar_char);

   _vcop_vloop_done();
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
}

void vcop_sobelY_3x3_2D_uchar_char_custom(
   __vptr_uint8 in,
   __vptr_int8 coef,
   __vptr_int8 out,
   int img_w,
   int img_h,
   int out_w,
   int out_h,
   int comp_w,
   int comp_h,
   int in_type,
   int coef_type,
   int out_type,
   int round_shift,
   unsigned short pblock[])
{
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
   vcop_sobelY_3x3_2D_uchar_char_init(in, coef, out, img_w, img_h, out_w, out_h, comp_w, comp_h, in_type, coef_type, out_type, round_shift, pblock);

   VCOP_BUF_SWITCH_SET(WBUF_VCOP, IBUFHB_VCOP, IBUFLB_VCOP,
                   IBUFHA_VCOP, IBUFLA_VCOP);
   vcop_sobelY_3x3_2D_uchar_char_vloops(pblock);

   _vcop_vloop_done();
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
}
#endif
//#pragma DATA_SECTION(__pblock_vcop_sobel_magnitude, ".vcop_parameter_block")
//#pragma DATA_ALIGN(__pblock_vcop_sobel_magnitude, __ALIGNOF__(int));
unsigned short * __pblock_vcop_sobel_magnitude; //[24];

unsigned int vcop_sobel_magnitude_param_count(void)
{
   return 24u;
}

unsigned int vcop_sobel_magnitude_ctrl_count(void)
{
   return 0u;
}

unsigned int vcop_sobel_magnitude_init(
   __vptr_int8 inX,
   __vptr_int8 inY,
   __vptr_uint8 out,
   unsigned short blk_w,
   unsigned short blk_h,
   unsigned short out_w,
   unsigned short pblock[])
{
   int __offset = 0;
   /* Loop 1 PREGS */
   __vcop_pblock_init16(pblock, __offset+_PREG(2), 0);
   __vcop_pblock_init16(pblock, __offset+_PREG(3), 0);
   __vcop_pblock_init16(pblock, __offset+_PREG(4), (blk_h)-1u);
   __vcop_pblock_init16(pblock, __offset+_PREG(5), (blk_w/(2 * (8u)))-1u);
   __vcop_pblock_init32(pblock, __offset+_PREG(6), 20);
   __vcop_pblock_init32(pblock, __offset+_PREG(8), 128);
   __vcop_pblock_init32(pblock, __offset+_PREG(10), 255);
   __vcop_pblock_init32(pblock, __offset+_PREG(12), (uchar *)inX+2);
   __vcop_pblock_init32(pblock, __offset+_PREG(14), (uchar *)inY+2);
   __vcop_pblock_init32(pblock, __offset+_PREG(16), (uchar *)out);
   __vcop_pblock_init16(pblock, __offset+_PREG(18), 16);
   __vcop_pblock_init16(pblock, __offset+_PREG(19), (2*blk_w*sizeof(*inX)) -(2*(8u*sizeof(*inX)))*((blk_w/(2 * (8u)))-1u));
   __vcop_pblock_init16(pblock, __offset+_PREG(20), 8);
   __vcop_pblock_init16(pblock, __offset+_PREG(21), (out_w*sizeof(*inX)) -((8u*sizeof(*inX)))*((blk_w/(2 * (8u)))-1u));
   __vcop_pblock_init32(pblock, __offset+_PREG(22), 0);
   __vcop_pblock_init32(pblock, __offset+_PREG(24), 2);
   __offset += 24;

   return 24u;
}

void vcop_sobel_magnitude_vloops(
   unsigned short pblock[])
{
   /* Kernel-wide Vector Registers */
   #pragma VCC_VREG("V128", 16);
   #pragma VCC_VREG("V255", 17);
   #pragma VCC_VREG("VT", 18);
   #pragma VCC_VREG("Vin1", 19);
   #pragma VCC_VREG("Vin2", 20);
   #pragma VCC_VREG("Vin3", 21);
   #pragma VCC_VREG("Vin4", 22);
   #pragma VCC_VREG("Vone", 23);
   #pragma VCC_VREG("Vout_e", 24);
   #pragma VCC_VREG("Vout_o", 25);
   #pragma VCC_VREG("Vsc", 26);
   #pragma VCC_VREG("Vzero", 27);

   __vcop_param(&pblock[0]);

   /* VLOOP 1 Start */

   /* VLOOP Local Vector Registers */
   

   /* VLOOP Local Address Generators */
   #pragma EVE_REG("Addr_in", "A0");
   #pragma EVE_REG("Addr_ou", "A1");
   /* VLOOP Loop Control Variables   */
   #pragma EVE_REG("I1", "I3");
   #pragma EVE_REG("I2", "I4");
   

   __vcop_vloop(__vcop_compute(), 17u, 12u, 1u);
   __vcop_vinit(__vcop_sizeW(), __vcop_once(), _PREG(22), _VREG(27));
   __vcop_vinit(__vcop_sizeW(), __vcop_once(), _PREG(24), _VREG(26));
   __vcop_vinit(__vcop_sizeW(), __vcop_once(), _PREG(6), _VREG(18));
   __vcop_vinit(__vcop_sizeW(), __vcop_once(), _PREG(8), _VREG(16));
   __vcop_vinit(__vcop_sizeW(), __vcop_once(), _PREG(10), _VREG(17));
   __vcop_vagen(_AGEN(0), _PREG(18), _PREG(19), _PREG(0), _PREG(0));
   __vcop_vagen(_AGEN(1), _PREG(20), _PREG(21), _PREG(0), _PREG(0));
   __vcop_vload(__vcop_sizeB(), __vcop_dintrlv(), _PREG(12), _AGEN(0), _VPAIR(19,20), __vcop_alws_condload());
   __vcop_vload(__vcop_sizeB(), __vcop_dintrlv(), _PREG(14), _AGEN(0), _VPAIR(21,22), __vcop_alws_condload());
   __vcop_vabs(_VREG(19), _VREG(24));
   __vcop_vabs(_VREG(20), _VREG(25));
   __vcop_vsad(_VREG(21), _VREG(27), _VREG(24));
   __vcop_vsad(_VREG(22), _VREG(27), _VREG(25));
   __vcop_vadd(_VREG(24), _VREG(25), _VREG(24));
   __vcop_vmpy(_VREG(24), _VREG(26), _VREG(24), _PREG(0));
   __vcop_vstore(__vcop_unconditional(), __vcop_sizeBU(), __vcop_npt(), __vcop_alws(), _VREG(24), _PREG(16), _AGEN(1), _PREG(0));
   __vcop_vloop_end(1u);

}

void vcop_sobel_magnitude(
   __vptr_int8 inX,
   __vptr_int8 inY,
   __vptr_uint8 out,
   unsigned short blk_w,
   unsigned short blk_h,
   unsigned short out_w)
{
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
   vcop_sobel_magnitude_init(inX, inY, out, blk_w, blk_h, out_w, __pblock_vcop_sobel_magnitude);

   VCOP_BUF_SWITCH_SET(WBUF_VCOP, IBUFHB_VCOP, IBUFLB_VCOP,
                   IBUFHA_VCOP, IBUFLA_VCOP);
   vcop_sobel_magnitude_vloops(__pblock_vcop_sobel_magnitude);

   _vcop_vloop_done();
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
}

void vcop_sobel_magnitude_custom(
   __vptr_int8 inX,
   __vptr_int8 inY,
   __vptr_uint8 out,
   unsigned short blk_w,
   unsigned short blk_h,
   unsigned short out_w,
   unsigned short pblock[])
{
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
   vcop_sobel_magnitude_init(inX, inY, out, blk_w, blk_h, out_w, pblock);

   VCOP_BUF_SWITCH_SET(WBUF_VCOP, IBUFHB_VCOP, IBUFLB_VCOP,
                   IBUFHA_VCOP, IBUFLA_VCOP);
   vcop_sobel_magnitude_vloops(pblock);

   _vcop_vloop_done();
   VCOP_BUF_SWITCH_SET(WBUF_SYST, IBUFHB_SYST, IBUFLB_SYST,
                   IBUFHA_SYST, IBUFLA_SYST);
}

