OpenCores
URL https://opencores.org/ocsvn/xucpu/xucpu/trunk

Subversion Repositories xucpu

[/] [xucpu/] [trunk/] [VHDL/] [ALU.vhdl] - Blame information for rev 24

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 lcdsgmtr
-- Copyright 2015, Jürgen Defurne
2
--
3
-- This file is part of the Experimental Unstable CPU System.
4
--
5
-- The Experimental Unstable CPU System Is free software: you can redistribute
6
-- it and/or modify it under the terms of the GNU Lesser General Public License
7
-- as published by the Free Software Foundation, either version 3 of the
8
-- License, or (at your option) any later version.
9
--
10
-- The Experimental Unstable CPU System is distributed in the hope that it will
11
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
13
-- General Public License for more details.
14
--
15
-- You should have received a copy of the GNU Lesser General Public License
16
-- along with Experimental Unstable CPU System. If not, see
17
-- http://www.gnu.org/licenses/lgpl.txt.
18
 
19
 
20
LIBRARY IEEE;
21
USE IEEE.STD_LOGIC_1164.ALL;
22
 
23
ENTITY ALU IS
24
  PORT (A   : IN  STD_LOGIC_VECTOR (15 DOWNTO 0);
25
        B   : IN  STD_LOGIC_VECTOR (15 DOWNTO 0);
26
        X   : OUT STD_LOGIC_VECTOR (15 DOWNTO 0);
27
        SEL : IN  STD_LOGIC_VECTOR (5 DOWNTO 0));
28
END ALU;
29
 
30
ARCHITECTURE Behavioral OF ALU IS
31
 
32
  COMPONENT boole IS
33
    GENERIC (
34
      width : NATURAL := 32);
35
    PORT (A   : IN  STD_LOGIC_VECTOR (width - 1 DOWNTO 0);
36
          B   : IN  STD_LOGIC_VECTOR (width - 1 DOWNTO 0);
37
          X   : OUT STD_LOGIC_VECTOR (width - 1 DOWNTO 0);
38
          SEL : IN  STD_LOGIC_VECTOR (2 DOWNTO 0));
39
  END COMPONENT boole;
40
 
41
  COMPONENT shift IS
42
    GENERIC (
43
      width : NATURAL := 16);
44
    PORT (A   : IN  STD_LOGIC_VECTOR (width - 1 DOWNTO 0);
45
          B   : IN  STD_LOGIC_VECTOR (width - 1 DOWNTO 0);
46
          X   : OUT STD_LOGIC_VECTOR (width - 1 DOWNTO 0);
47
          SEL : IN  STD_LOGIC_VECTOR (2 DOWNTO 0));
48
  END COMPONENT shift;
49
 
50
  COMPONENT addsub IS
51
    PORT (A     : IN  STD_LOGIC_VECTOR (15 DOWNTO 0);
52
          B     : IN  STD_LOGIC_VECTOR (15 DOWNTO 0);
53
          SUM   : OUT STD_LOGIC_VECTOR (15 DOWNTO 0);
54
          CARRY : OUT STD_LOGIC_VECTOR (15 DOWNTO 0);
55
          SEL   : IN  STD_LOGIC_VECTOR (1 DOWNTO 0));
56
  END COMPONENT addsub;
57
 
58
  COMPONENT multiplier IS
59
    PORT (A            : IN  STD_LOGIC_VECTOR (15 DOWNTO 0);
60
          B            : IN  STD_LOGIC_VECTOR (15 DOWNTO 0);
61
          PRODUCT_HIGH : OUT STD_LOGIC_VECTOR (15 DOWNTO 0);
62
          PRODUCT_LOW  : OUT STD_LOGIC_VECTOR (15 DOWNTO 0));
63
  END COMPONENT multiplier;
64
 
65
  SIGNAL bool_out      : STD_LOGIC_VECTOR(15 DOWNTO 0);
66
  SIGNAL shift_out     : STD_LOGIC_VECTOR(15 DOWNTO 0);
67
  SIGNAL add_out       : STD_LOGIC_VECTOR(15 DOWNTO 0);
68
  SIGNAL carry_out     : STD_LOGIC_VECTOR(15 DOWNTO 0);
69
  SIGNAL prod_low_out  : STD_LOGIC_VECTOR(15 DOWNTO 0);
70
  SIGNAL prod_high_out : STD_LOGIC_VECTOR(15 DOWNTO 0);
71
 
72
BEGIN
73
 
74
  BOOL1 : boole
75
    GENERIC MAP (
76
      width => 16)
77
    PORT MAP (
78
    A   => A,
79
    B   => B,
80
    X   => bool_out,
81
    SEL => SEL(2 DOWNTO 0));
82
 
83
  SHIFT1 : shift PORT MAP (
84
    A   => A,
85
    B   => B,
86
    X   => shift_out,
87
    SEL => SEL(2 DOWNTO 0));
88
 
89
  ADD1 : addsub PORT MAP (
90
    A     => A,
91
    B     => B,
92
    SUM   => add_out,
93
    CARRY => carry_out,
94
    SEL   => SEL(1 DOWNTO 0));
95
 
96
  MULT1 : multiplier PORT MAP (
97
    A            => A,
98
    B            => B,
99
    PRODUCT_HIGH => prod_high_out,
100
    PRODUCT_LOW  => prod_low_out);
101
 
102
  WITH SEL(5 DOWNTO 3) SELECT
103
    X <=
104
    bool_out      WHEN "000",
105
    shift_out     WHEN "001",
106
    add_out       WHEN "010",
107
    carry_out     WHEN "011",
108
    prod_low_out  WHEN "100",
109
    prod_high_out WHEN "101",
110
    X"0000"       WHEN OTHERS;
111
 
112
END Behavioral;
113
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.