[2] | 1 | #ifdef VHDL |
---|
| 2 | /* |
---|
| 3 | * $Id$ |
---|
| 4 | * |
---|
| 5 | * [ Description ] |
---|
| 6 | * |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #include "Behavioural/Generic/Shifter/include/Shifter.h" |
---|
| 10 | |
---|
| 11 | namespace morpheo { |
---|
| 12 | namespace behavioural { |
---|
| 13 | namespace generic { |
---|
| 14 | namespace shifter { |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | void Shifter::vhdl_body (Vhdl & vhdl) |
---|
| 18 | { |
---|
| 19 | //uint32_t log2_size_data = static_cast<uint32_t>(ceil(log2(_param._size_data))); |
---|
| 20 | |
---|
| 21 | vhdl.set_body ("-- Compute all case of shift"); |
---|
| 22 | |
---|
| 23 | for (uint32_t i=0; i<_param._nb_port; i++) |
---|
| 24 | { |
---|
| 25 | //-----[ Shift logic Left ]-------------------------------------------- |
---|
| 26 | if (_param._have_shift_logic_left) |
---|
| 27 | vhdl.set_body ("shift_logic_left_"+toString(i)+" <= TO_STDLOGICVECTOR(TO_BITVECTOR(in_SHIFTER_DATA_"+toString(i)+") sll CONV_INTEGER(shift_"+toString(i)+"));"); |
---|
| 28 | //-----[ Shift logic Right ]------------------------------------------- |
---|
| 29 | if (_param._have_shift_logic_right) |
---|
| 30 | vhdl.set_body ("shift_logic_right_"+toString(i)+" <= TO_STDLOGICVECTOR(TO_BITVECTOR(in_SHIFTER_DATA_"+toString(i)+") srl CONV_INTEGER(shift_"+toString(i)+"));"); |
---|
| 31 | //-----[ Shift arithmetic Left ]--------------------------------------- |
---|
| 32 | if (_param._have_shift_arithmetic_left) |
---|
| 33 | vhdl.set_body ("shift_arithmetic_left_"+toString(i)+" <= TO_STDLOGICVECTOR(TO_BITVECTOR(in_SHIFTER_DATA_"+toString(i)+") sla CONV_INTEGER(shift_"+toString(i)+"));"); |
---|
| 34 | //-----[ Shift arithmetic Right ]-------------------------------------- |
---|
| 35 | if (_param._have_shift_arithmetic_right) |
---|
| 36 | vhdl.set_body ("shift_arithmetic_right_"+toString(i)+" <= TO_STDLOGICVECTOR(TO_BITVECTOR(in_SHIFTER_DATA_"+toString(i)+") sra CONV_INTEGER(shift_"+toString(i)+"));"); |
---|
| 37 | //-----[ Rotate Left ]------------------------------------------------- |
---|
| 38 | if (_param._have_rotate_left) |
---|
| 39 | vhdl.set_body ("rotate_left_"+toString(i)+" <= TO_STDLOGICVECTOR(TO_BITVECTOR(in_SHIFTER_DATA_"+toString(i)+") rol CONV_INTEGER(shift_"+toString(i)+"));"); |
---|
| 40 | //-----[ Rotate Right ]------------------------------------------------ |
---|
| 41 | if (_param._have_rotate_right) |
---|
| 42 | vhdl.set_body ("rotate_right_"+toString(i)+" <= TO_STDLOGICVECTOR(TO_BITVECTOR(in_SHIFTER_DATA_"+toString(i)+") ror CONV_INTEGER(shift_"+toString(i)+"));"); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | if (_param._size_data_completion > 0) |
---|
| 46 | { |
---|
| 47 | vhdl.set_body (""); |
---|
| 48 | vhdl.set_body ("-- Mask"); |
---|
| 49 | |
---|
| 50 | for (uint32_t i=0; i<_param._nb_port; i++) |
---|
| 51 | { |
---|
| 52 | string print_shifter_completion; |
---|
| 53 | |
---|
| 54 | if (_param._type_completion_bool == true) |
---|
| 55 | print_shifter_completion = "in_SHIFTER_CARRY_IN"; |
---|
| 56 | else |
---|
| 57 | print_shifter_completion = "in_SHIFTER_COMPLETION"; |
---|
| 58 | |
---|
| 59 | if (_param._size_data == _param._size_data_completion) |
---|
| 60 | { |
---|
| 61 | vhdl.set_body ("shifter_completion_left_"+toString(i)+" <= "+print_shifter_completion+"_"+toString(i)+";"); |
---|
| 62 | vhdl.set_body ("shifter_completion_right_"+toString(i)+" <= "+print_shifter_completion+"_"+toString(i)+";"); |
---|
| 63 | } |
---|
| 64 | else |
---|
| 65 | { |
---|
| 66 | vhdl.set_body ("shifter_completion_left_"+toString(i)+std_logic_range(_param._size_data-1,_param._size_data_completion)+" <= "+std_logic_others(_param._size_data-_param._size_data_completion,0)+";"); |
---|
| 67 | vhdl.set_body ("shifter_completion_left_"+toString(i)+std_logic_range(_param._size_data_completion )+" <= "+print_shifter_completion+"_"+toString(i)+";"); |
---|
| 68 | |
---|
| 69 | vhdl.set_body ("shifter_completion_right_"+toString(i)+std_logic_range(_param._size_data-1,_param._size_data-_param._size_data_completion)+" <= "+print_shifter_completion+"_"+toString(i)+";"); |
---|
| 70 | vhdl.set_body ("shifter_completion_right_"+toString(i)+std_logic_range(_param._size_data-_param._size_data_completion )+" <= "+std_logic_others(_param._size_data-_param._size_data_completion,0)+";"); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | vhdl.set_body ("mask_completion_left_"+toString(i)+" <= TO_STDLOGICVECTOR(TO_BITVECTOR(cst_completion) sll CONV_INTEGER(shift_"+toString(i)+"));"); |
---|
| 74 | vhdl.set_body ("mask_completion_right_"+toString(i)+" <= TO_STDLOGICVECTOR(TO_BITVECTOR(cst_completion) srl CONV_INTEGER(shift_"+toString(i)+"));"); |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | vhdl.set_body (""); |
---|
| 80 | vhdl.set_body ("-- Multiplexor"); |
---|
| 81 | |
---|
| 82 | for (uint32_t i=0; i<_param._nb_port; i++) |
---|
| 83 | { |
---|
| 84 | vhdl.set_body ("out_SHIFTER_DATA_"+toString(i)+" <="); |
---|
| 85 | string print_else = " "; |
---|
| 86 | |
---|
| 87 | //-----[ Shift arithmetic Left ]--------------------------------------- |
---|
| 88 | if (_param._have_shift_arithmetic_left) |
---|
| 89 | { |
---|
| 90 | bool have_when = false; |
---|
| 91 | string print_when = ""; |
---|
| 92 | string print_and = ""; |
---|
| 93 | |
---|
| 94 | if (_param._direction == external_direction) |
---|
| 95 | { |
---|
| 96 | have_when = true; |
---|
| 97 | print_when += " in_SHIFTER_DIRECTION_"+toString(i)+" = cst_is_direction_left "; |
---|
| 98 | print_and = " and "; |
---|
| 99 | } |
---|
| 100 | if (_param._rotate == external_rotate) |
---|
| 101 | { |
---|
| 102 | have_when = true; |
---|
| 103 | print_when += print_and+" in_SHIFTER_TYPE_"+toString(i)+" = cst_is_type_shift "; |
---|
| 104 | print_and = " and "; |
---|
| 105 | } |
---|
| 106 | if (_param._carry == external_carry) |
---|
| 107 | { |
---|
| 108 | have_when = true; |
---|
| 109 | print_when += print_and+" in_SHIFTER_CARRY_"+toString(i)+" = cst_is_carry_arithmetic"; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | if (have_when) |
---|
| 113 | print_when = "when " + print_when; |
---|
| 114 | |
---|
| 115 | vhdl.set_body ("\t"+print_else+" shift_arithmetic_left_"+toString(i)+" "+print_when); |
---|
| 116 | print_else = "else"; |
---|
| 117 | } |
---|
| 118 | //-----[ Shift arithmetic Right ]-------------------------------------- |
---|
| 119 | if (_param._have_shift_arithmetic_right) |
---|
| 120 | { |
---|
| 121 | bool have_when = false; |
---|
| 122 | string print_when = ""; |
---|
| 123 | string print_and = ""; |
---|
| 124 | |
---|
| 125 | if (_param._direction == external_direction) |
---|
| 126 | { |
---|
| 127 | have_when = true; |
---|
| 128 | print_when += " in_SHIFTER_DIRECTION_"+toString(i)+" = cst_is_direction_right"; |
---|
| 129 | print_and = " and "; |
---|
| 130 | } |
---|
| 131 | if (_param._rotate == external_rotate) |
---|
| 132 | { |
---|
| 133 | have_when = true; |
---|
| 134 | print_when += print_and+" in_SHIFTER_TYPE_"+toString(i)+" = cst_is_type_shift "; |
---|
| 135 | print_and = " and "; |
---|
| 136 | } |
---|
| 137 | if (_param._carry == external_carry) |
---|
| 138 | { |
---|
| 139 | have_when = true; |
---|
| 140 | print_when += print_and+" in_SHIFTER_CARRY_"+toString(i)+" = cst_is_carry_arithmetic"; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | if (have_when) |
---|
| 144 | print_when = "when " + print_when; |
---|
| 145 | |
---|
| 146 | vhdl.set_body ("\t"+print_else+" shift_arithmetic_right_"+toString(i)+" "+print_when); |
---|
| 147 | print_else = "else"; |
---|
| 148 | } |
---|
| 149 | //-----[ Shift logic Left ]-------------------------------------------- |
---|
| 150 | if (_param._have_shift_logic_left) |
---|
| 151 | { |
---|
| 152 | bool have_when = false; |
---|
| 153 | string print_when = ""; |
---|
| 154 | string print_and = ""; |
---|
| 155 | |
---|
| 156 | if (_param._direction == external_direction) |
---|
| 157 | { |
---|
| 158 | have_when = true; |
---|
| 159 | print_when += " in_SHIFTER_DIRECTION_"+toString(i)+" = cst_is_direction_left "; |
---|
| 160 | print_and = " and "; |
---|
| 161 | } |
---|
| 162 | if (_param._rotate == external_rotate) |
---|
| 163 | { |
---|
| 164 | have_when = true; |
---|
| 165 | print_when += print_and+" in_SHIFTER_TYPE_"+toString(i)+" = cst_is_type_shift "; |
---|
| 166 | print_and = " and "; |
---|
| 167 | } |
---|
| 168 | if (_param._carry == external_carry) |
---|
| 169 | { |
---|
| 170 | have_when = true; |
---|
| 171 | print_when += print_and+" in_SHIFTER_CARRY_"+toString(i)+" = cst_is_carry_logic "; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | if (have_when) |
---|
| 175 | print_when = "when " + print_when; |
---|
| 176 | |
---|
| 177 | string print_expr_completion; |
---|
| 178 | |
---|
| 179 | if (_param._size_data_completion == 0) |
---|
| 180 | print_expr_completion = "shift_logic_left_"+toString(i)+" "; |
---|
| 181 | else |
---|
| 182 | print_expr_completion = "(shift_logic_left_"+toString(i)+" and mask_completion_left_"+toString(i)+" ) or ( shifter_completion_left_"+toString(i)+" and not mask_completion_left_"+toString(i)+" )"; |
---|
| 183 | |
---|
| 184 | vhdl.set_body ("\t"+print_else+" "+print_expr_completion+" "+print_when); |
---|
| 185 | print_else = "else"; |
---|
| 186 | } |
---|
| 187 | //-----[ Shift logic Right ]------------------------------------------- |
---|
| 188 | if (_param._have_shift_logic_right) |
---|
| 189 | { |
---|
| 190 | bool have_when = false; |
---|
| 191 | string print_when = ""; |
---|
| 192 | string print_and = ""; |
---|
| 193 | |
---|
| 194 | if (_param._direction == external_direction) |
---|
| 195 | { |
---|
| 196 | have_when = true; |
---|
| 197 | print_when += " in_SHIFTER_DIRECTION_"+toString(i)+" = cst_is_direction_right"; |
---|
| 198 | print_and = " and "; |
---|
| 199 | } |
---|
| 200 | if (_param._rotate == external_rotate) |
---|
| 201 | { |
---|
| 202 | have_when = true; |
---|
| 203 | print_when += print_and+" in_SHIFTER_TYPE_"+toString(i)+" = cst_is_type_shift "; |
---|
| 204 | print_and = " and "; |
---|
| 205 | } |
---|
| 206 | if (_param._carry == external_carry) |
---|
| 207 | { |
---|
| 208 | have_when = true; |
---|
| 209 | print_when += print_and+" in_SHIFTER_CARRY_"+toString(i)+" = cst_is_carry_logic "; |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | if (have_when) |
---|
| 213 | print_when = "when " + print_when; |
---|
| 214 | |
---|
| 215 | string print_expr_completion; |
---|
| 216 | |
---|
| 217 | if (_param._size_data_completion == 0) |
---|
| 218 | print_expr_completion = "shift_logic_right_"+toString(i); |
---|
| 219 | else |
---|
| 220 | print_expr_completion = "(shift_logic_right_"+toString(i)+" and mask_completion_right_"+toString(i)+") or ( shifter_completion_right_"+toString(i)+" and not mask_completion_right_"+toString(i)+")"; |
---|
| 221 | |
---|
| 222 | vhdl.set_body ("\t"+print_else+" "+print_expr_completion+" "+print_when); |
---|
| 223 | print_else = "else"; |
---|
| 224 | } |
---|
| 225 | //-----[ Rotate Left ]------------------------------------------------- |
---|
| 226 | if (_param._have_rotate_left) |
---|
| 227 | { |
---|
| 228 | bool have_when = false; |
---|
| 229 | string print_when = ""; |
---|
| 230 | string print_and = ""; |
---|
| 231 | |
---|
| 232 | if (_param._direction == external_direction) |
---|
| 233 | { |
---|
| 234 | have_when = true; |
---|
| 235 | print_when += " in_SHIFTER_DIRECTION_"+toString(i)+" = cst_is_direction_left "; |
---|
| 236 | print_and = " and "; |
---|
| 237 | } |
---|
| 238 | if (_param._rotate == external_rotate) |
---|
| 239 | { |
---|
| 240 | have_when = true; |
---|
| 241 | print_when += print_and+" in_SHIFTER_TYPE_"+toString(i)+" = cst_is_type_rotate"; |
---|
| 242 | print_and = " and "; |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | if (have_when) |
---|
| 246 | print_when = "when " + print_when; |
---|
| 247 | |
---|
| 248 | vhdl.set_body ("\t"+print_else+" rotate_left_"+toString(i)+" "+print_when); |
---|
| 249 | print_else = "else"; |
---|
| 250 | } |
---|
| 251 | //-----[ Rotate Right ]------------------------------------------------ |
---|
| 252 | if (_param._have_rotate_right) |
---|
| 253 | { |
---|
| 254 | bool have_when = false; |
---|
| 255 | string print_when = ""; |
---|
| 256 | string print_and = ""; |
---|
| 257 | |
---|
| 258 | if (_param._direction == external_direction) |
---|
| 259 | { |
---|
| 260 | have_when = true; |
---|
| 261 | print_when += " in_SHIFTER_DIRECTION_"+toString(i)+" = cst_is_direction_right"; |
---|
| 262 | print_and = " and "; |
---|
| 263 | } |
---|
| 264 | if (_param._rotate == external_rotate) |
---|
| 265 | { |
---|
| 266 | have_when = true; |
---|
| 267 | print_when += print_and+" in_SHIFTER_TYPE_"+toString(i)+" = cst_is_type_rotate"; |
---|
| 268 | print_and = " and "; |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | if (have_when) |
---|
| 272 | print_when = "when " + print_when; |
---|
| 273 | |
---|
| 274 | vhdl.set_body ("\t"+print_else+" rotate_right_"+toString(i)+" "+print_when); |
---|
| 275 | print_else = "else"; |
---|
| 276 | } |
---|
| 277 | vhdl.set_body (";"); |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | }; |
---|
| 281 | /* |
---|
| 282 | //-----[ Shift logic Left ]-------------------------------------------- |
---|
| 283 | if (_param._have_shift_logic_left) |
---|
| 284 | { |
---|
| 285 | |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | //-----[ Shift logic Right ]------------------------------------------- |
---|
| 289 | if (_param._have_shift_logic_right) |
---|
| 290 | { |
---|
| 291 | |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | //-----[ Shift arithmetic Left ]--------------------------------------- |
---|
| 295 | if (_param._have_shift_arithmetic_left) |
---|
| 296 | { |
---|
| 297 | |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | //-----[ Shift arithmetic Right ]-------------------------------------- |
---|
| 301 | if (_param._have_shift_arithmetic_right) |
---|
| 302 | { |
---|
| 303 | |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | //-----[ Rotate Left ]------------------------------------------------- |
---|
| 307 | if (_param._have_rotate_left) |
---|
| 308 | { |
---|
| 309 | |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | //-----[ Rotate Right ]------------------------------------------------ |
---|
| 313 | if (_param._have_rotate_right) |
---|
| 314 | { |
---|
| 315 | |
---|
| 316 | } |
---|
| 317 | */ |
---|
| 318 | }; // end namespace shifter |
---|
| 319 | }; // end namespace generic |
---|
| 320 | }; // end namespace behavioural |
---|
| 321 | }; // end namespace morpheo |
---|
| 322 | #endif |
---|