| | 232 | == 生成結果(単精度相当) == |
| | 233 | {{{ |
| | 234 | library ieee; |
| | 235 | use ieee.std_logic_1164.all; |
| | 236 | use ieee.std_logic_unsigned.all; |
| | 237 | |
| | 238 | |
| | 239 | entity fp_add_32_23_8_4 is |
| | 240 | port ( |
| | 241 | x : in std_logic_vector(31 downto 0); |
| | 242 | y : in std_logic_vector(31 downto 0); |
| | 243 | z : out std_logic_vector(31 downto 0); |
| | 244 | clk : in std_logic |
| | 245 | ); |
| | 246 | end fp_add_32_23_8_4; |
| | 247 | |
| | 248 | |
| | 249 | architecture source of fp_add_32_23_8_4 is |
| | 250 | |
| | 251 | component extract_32_23_8 |
| | 252 | port ( |
| | 253 | x : in std_logic_vector(31 downto 0); |
| | 254 | s : out std_logic; |
| | 255 | m : out std_logic_vector(23 downto 0); |
| | 256 | e : out std_logic_vector(7 downto 0) |
| | 257 | ); |
| | 258 | end component; |
| | 259 | |
| | 260 | component rounding_32_23_8 |
| | 261 | port ( |
| | 262 | m : in std_logic_vector(23 downto 0); |
| | 263 | e : in std_logic_vector(7 downto 0); |
| | 264 | u : in std_logic; |
| | 265 | r : in std_logic; |
| | 266 | s : in std_logic; |
| | 267 | mout : out std_logic_vector(23 downto 0); |
| | 268 | eout : out std_logic_vector(7 downto 0) |
| | 269 | ); |
| | 270 | end component; |
| | 271 | |
| | 272 | component compose_32_23_8 |
| | 273 | port ( |
| | 274 | s : in std_logic; |
| | 275 | m : in std_logic_vector(23 downto 0); |
| | 276 | e : in std_logic_vector(7 downto 0); |
| | 277 | z : out std_logic_vector(31 downto 0); |
| | 278 | clk : in std_logic |
| | 279 | ); |
| | 280 | end component; |
| | 281 | |
| | 282 | component swap_32 |
| | 283 | port ( |
| | 284 | f : in std_logic; |
| | 285 | x : in std_logic_vector(31 downto 0); |
| | 286 | y : in std_logic_vector(31 downto 0); |
| | 287 | xs : out std_logic_vector(31 downto 0); |
| | 288 | ys : out std_logic_vector(31 downto 0) |
| | 289 | ); |
| | 290 | end component; |
| | 291 | |
| | 292 | component int_rshift_24_9_0 |
| | 293 | port ( |
| | 294 | c : in std_logic_vector(8 downto 0); |
| | 295 | i : in std_logic_vector(23 downto 0); |
| | 296 | o : out std_logic_vector(27 downto 0) |
| | 297 | ); |
| | 298 | end component; |
| | 299 | |
| | 300 | component int_extractsbit_24_9_0 |
| | 301 | port ( |
| | 302 | c : in std_logic_vector(8 downto 0); |
| | 303 | i : in std_logic_vector(23 downto 0); |
| | 304 | s : out std_logic |
| | 305 | ); |
| | 306 | end component; |
| | 307 | |
| | 308 | component int_sadder_29_2 |
| | 309 | port ( |
| | 310 | x : in std_logic_vector(28 downto 0); |
| | 311 | sx : in std_logic; |
| | 312 | y : in std_logic_vector(28 downto 0); |
| | 313 | sy : in std_logic; |
| | 314 | z : out std_logic_vector(28 downto 0); |
| | 315 | sz : out std_logic; |
| | 316 | clk : in std_logic |
| | 317 | ); |
| | 318 | end component; |
| | 319 | |
| | 320 | component fp_addtest_32_23_8_0 |
| | 321 | port ( |
| | 322 | tmp : in std_logic_vector(27 downto 0); |
| | 323 | exp : in std_logic_vector(7 downto 0); |
| | 324 | r1 : in std_logic; |
| | 325 | r2 : in std_logic; |
| | 326 | r3 : in std_logic; |
| | 327 | res : out std_logic_vector(23 downto 0); |
| | 328 | expz : out std_logic_vector(7 downto 0); |
| | 329 | ulp : out std_logic; |
| | 330 | rbit : out std_logic; |
| | 331 | sbit : out std_logic; |
| | 332 | clk : in std_logic |
| | 333 | ); |
| | 334 | end component; |
| | 335 | |
| | 336 | component underflow_24_8 |
| | 337 | port ( |
| | 338 | f : in std_logic; |
| | 339 | m1 : in std_logic_vector(23 downto 0); |
| | 340 | e1 : in std_logic_vector(7 downto 0); |
| | 341 | u1 : in std_logic; |
| | 342 | r1 : in std_logic; |
| | 343 | s1 : in std_logic; |
| | 344 | m2 : in std_logic_vector(23 downto 0); |
| | 345 | e2 : in std_logic_vector(7 downto 0); |
| | 346 | u2 : in std_logic; |
| | 347 | r2 : in std_logic; |
| | 348 | s2 : in std_logic; |
| | 349 | m : out std_logic_vector(23 downto 0); |
| | 350 | e : out std_logic_vector(7 downto 0); |
| | 351 | u : out std_logic; |
| | 352 | r : out std_logic; |
| | 353 | s : out std_logic |
| | 354 | ); |
| | 355 | end component; |
| | 356 | |
| | 357 | component delay_1_2 |
| | 358 | port ( |
| | 359 | i : in std_logic; |
| | 360 | o : out std_logic; |
| | 361 | clk : in std_logic |
| | 362 | ); |
| | 363 | end component; |
| | 364 | |
| | 365 | component delay_8_2 |
| | 366 | port ( |
| | 367 | i : in std_logic_vector(7 downto 0); |
| | 368 | o : out std_logic_vector(7 downto 0); |
| | 369 | clk : in std_logic |
| | 370 | ); |
| | 371 | end component; |
| | 372 | |
| | 373 | component delay_1_3 |
| | 374 | port ( |
| | 375 | i : in std_logic; |
| | 376 | o : out std_logic; |
| | 377 | clk : in std_logic |
| | 378 | ); |
| | 379 | end component; |
| | 380 | |
| | 381 | component delay_8_3 |
| | 382 | port ( |
| | 383 | i : in std_logic_vector(7 downto 0); |
| | 384 | o : out std_logic_vector(7 downto 0); |
| | 385 | clk : in std_logic |
| | 386 | ); |
| | 387 | end component; |
| | 388 | |
| | 389 | component delay_9_3 |
| | 390 | port ( |
| | 391 | i : in std_logic_vector(8 downto 0); |
| | 392 | o : out std_logic_vector(8 downto 0); |
| | 393 | clk : in std_logic |
| | 394 | ); |
| | 395 | end component; |
| | 396 | |
| | 397 | component delay_24_3 |
| | 398 | port ( |
| | 399 | i : in std_logic_vector(23 downto 0); |
| | 400 | o : out std_logic_vector(23 downto 0); |
| | 401 | clk : in std_logic |
| | 402 | ); |
| | 403 | end component; |
| | 404 | |
| | 405 | |
| | 406 | |
| | 407 | signal signz,sz : std_logic; |
| | 408 | signal manz,mz : std_logic_vector(23 downto 0); |
| | 409 | signal expz,ez : std_logic_vector(7 downto 0); |
| | 410 | signal ex0, ey0 : std_logic_vector(8 downto 0); |
| | 411 | |
| | 412 | signal xx, yy : std_logic_vector(31 downto 0); |
| | 413 | signal sx, sy : std_logic; |
| | 414 | signal mx, my : std_logic_vector(23 downto 0); |
| | 415 | signal ex, ey : std_logic_vector(7 downto 0); |
| | 416 | |
| | 417 | signal dx : std_logic_vector(8 downto 0); |
| | 418 | signal dy : std_logic_vector(8 downto 0); |
| | 419 | signal diff : std_logic_vector(8 downto 0); |
| | 420 | |
| | 421 | -- |
| | 422 | signal res0 : std_logic_vector(23 downto 0); |
| | 423 | signal expz0 : std_logic_vector(7 downto 0); |
| | 424 | signal signz0 : std_logic; |
| | 425 | signal ulp0, rbit0, sbit0 : std_logic; |
| | 426 | |
| | 427 | signal res1 : std_logic_vector(23 downto 0); |
| | 428 | signal expz1 : std_logic_vector(7 downto 0); |
| | 429 | signal signz1 : std_logic; |
| | 430 | signal ulp1, rbit1, sbit1 : std_logic; |
| | 431 | |
| | 432 | -- |
| | 433 | signal o1 : std_logic_vector(27 downto 0); |
| | 434 | signal o2 : std_logic_vector(27 downto 0); |
| | 435 | signal r1, r2, r3 : std_logic; |
| | 436 | |
| | 437 | signal a0, a1 : std_logic_vector(28 downto 0); |
| | 438 | signal b0, b1 : std_logic_vector(28 downto 0); |
| | 439 | signal res : std_logic_vector(28 downto 0); |
| | 440 | signal resn : std_logic_vector(28 downto 0); |
| | 441 | |
| | 442 | signal zf : std_logic; |
| | 443 | |
| | 444 | -- |
| | 445 | signal dd : std_logic_vector(9 downto 0); |
| | 446 | signal d0 : std_logic_vector(9 downto 0); |
| | 447 | signal manzz : std_logic_vector(23 downto 0); |
| | 448 | signal expzz : std_logic_vector(7 downto 0); |
| | 449 | signal ulp, rbit, sbit : std_logic; |
| | 450 | |
| | 451 | signal zz : std_logic_vector(31 downto 0); |
| | 452 | |
| | 453 | signal expz0_reg : std_logic_vector(7 downto 0); |
| | 454 | signal expz0_regg : std_logic_vector(7 downto 0); |
| | 455 | signal r1_reg, r2_reg, r3_reg : std_logic; |
| | 456 | signal diff_reg : std_logic_vector(8 downto 0); |
| | 457 | signal res0_reg : std_logic_vector(23 downto 0); |
| | 458 | signal signz0_reg : std_logic; |
| | 459 | signal signz1_reg : std_logic; |
| | 460 | signal ulp0_reg, rbit0_reg, sbit0_reg : std_logic; |
| | 461 | signal zf_reg : std_logic; |
| | 462 | |
| | 463 | begin |
| | 464 | ex0 <= '0'&x(30 downto 23); |
| | 465 | ey0 <= '0'&y(30 downto 23); |
| | 466 | |
| | 467 | dx <= ex0 - ey0; |
| | 468 | dy <= ey0 - ex0; |
| | 469 | |
| | 470 | -- swap |
| | 471 | s0 : swap_32 port map ( f => dx(8), x => x, y => y, xs => xx, ys => yy); |
| | 472 | |
| | 473 | with dx(8) select |
| | 474 | diff <= dy when '1', |
| | 475 | dx when others; |
| | 476 | |
| | 477 | e0 : extract_32_23_8 port map ( x => xx, s => sx, m => mx, e => ex); |
| | 478 | e1 : extract_32_23_8 port map ( x => yy, s => sy, m => my, e => ey); |
| | 479 | |
| | 480 | -------------------------------------------------------------------- |
| | 481 | -- if diff > 24 |
| | 482 | res0 <= mx; |
| | 483 | expz0 <= ex; |
| | 484 | signz0 <= sx; |
| | 485 | ulp0 <= res0(0); |
| | 486 | rbit0 <= '0'; |
| | 487 | sbit0 <= '1'; |
| | 488 | -- else |
| | 489 | -- o1 |
| | 490 | o1 <= "00"&mx&"00"; |
| | 491 | |
| | 492 | -- o2 |
| | 493 | shift0 : int_rshift_24_9_0 port map (c => diff, i => my, o => o2); |
| | 494 | |
| | 495 | r1 <= o2(1); |
| | 496 | r2 <= o2(0); |
| | 497 | |
| | 498 | -- r3 |
| | 499 | sb0 : int_extractsbit_24_9_0 port map (c => diff, i => my, s => r3); |
| | 500 | |
| | 501 | ---- |
| | 502 | a0 <= o1(27 downto 0)&'0'; |
| | 503 | b0 <= o2(27 downto 0)&r3; |
| | 504 | |
| | 505 | -- |
| | 506 | add: int_sadder_29_2 port map (x => a0, sx => sx, y => b0, sy => sy, |
| | 507 | z => resn, sz => signz1, clk => clk); |
| | 508 | |
| | 509 | d1 : delay_1_2 port map (i => r1, o => r1_reg, clk => clk); |
| | 510 | d2 : delay_1_2 port map (i => r2, o => r2_reg, clk => clk); |
| | 511 | d3 : delay_1_2 port map (i => r3, o => r3_reg, clk => clk); |
| | 512 | d4 : delay_8_2 port map (i => expz0, o => expz0_reg, clk => clk); |
| | 513 | |
| | 514 | -- flag zf if res == 0 |
| | 515 | with resn select |
| | 516 | zf <= '1' when "00000000000000000000000000000", |
| | 517 | '0' when others; |
| | 518 | ---- |
| | 519 | f0 : fp_addtest_32_23_8_0 port map ( tmp => resn(27 downto 0), |
| | 520 | exp => expz0_reg, r1 => r1_reg, r2 => r2_reg, r3 => r3_reg, |
| | 521 | res => res1, expz => expz1, ulp => ulp1, rbit => rbit1, sbit => sbit1, clk => clk); |
| | 522 | |
| | 523 | process(clk) begin |
| | 524 | if(clk'event and clk='1') then |
| | 525 | signz1_reg <= signz1; |
| | 526 | zf_reg <= zf; |
| | 527 | end if; |
| | 528 | end process; |
| | 529 | |
| | 530 | --sadd 2 signz1, resn |
| | 531 | --test 3 res1, expz1, ulp1, rbit1, sbit1 |
| | 532 | |
| | 533 | d5 : delay_1_3 port map (i => signz0, o => signz0_reg, clk => clk); |
| | 534 | d6 : delay_1_3 port map (i => ulp0, o => ulp0_reg, clk => clk); |
| | 535 | d7 : delay_1_3 port map (i => rbit0, o => rbit0_reg, clk => clk); |
| | 536 | d8 : delay_1_3 port map (i => sbit0, o => sbit0_reg, clk => clk); |
| | 537 | d9 : delay_8_3 port map (i => expz0, o => expz0_regg, clk => clk); |
| | 538 | d10 : delay_9_3 port map (i => diff, o => diff_reg, clk => clk); |
| | 539 | d11 : delay_24_3 port map (i => res0, o => res0_reg, clk => clk); |
| | 540 | |
| | 541 | -------------------------------------------------------------------- |
| | 542 | d0 <= '0'&diff_reg; |
| | 543 | dd <= "000011000" - d0; |
| | 544 | |
| | 545 | uf : underflow_24_8 port map (f => dd(8), |
| | 546 | m1 => res0_reg, e1 => expz0_regg, u1 => ulp0_reg, r1 => rbit0_reg, s1 => sbit0_reg, |
| | 547 | m2 => res1, e2 => expz1, u2 => ulp1, r2 => rbit1, s2 => sbit1, |
| | 548 | m => manzz, e => expzz, u => ulp, r => rbit, s => sbit ); |
| | 549 | |
| | 550 | with dd(8) select |
| | 551 | signz <= signz0_reg when '1', |
| | 552 | signz1_reg when others; |
| | 553 | |
| | 554 | r0 : rounding_32_23_8 port map ( m => manzz, e => expzz, u => ulp, r => rbit, s => sbit, |
| | 555 | mout => manz, eout=> expz); |
| | 556 | |
| | 557 | with zf_reg select |
| | 558 | sz <= signz when '0', |
| | 559 | '0' when others; |
| | 560 | |
| | 561 | with zf_reg select |
| | 562 | mz <= manz when '0', |
| | 563 | "000000000000000000000000" when others; |
| | 564 | |
| | 565 | with zf_reg select |
| | 566 | ez <= expz when '0', |
| | 567 | "00000000" when others; |
| | 568 | |
| | 569 | c0 : compose_32_23_8 port map (s => sz, m => mz, e => ez, z => z, clk => clk); |
| | 570 | end source; |
| | 571 | }}} |