Project

General

Profile

Download (2.61 KB) Statistics
| Branch: | Tag: | Revision:
1 d93979b7 Arnaud Dieumegard
2
-- Copyright (C) 1996 Morgan Kaufmann Publishers, Inc
3
4
-- This file is part of VESTs (Vhdl tESTs).
5
6
-- VESTs is free software; you can redistribute it and/or modify it
7
-- under the terms of the GNU General Public License as published by the
8
-- Free Software Foundation; either version 2 of the License, or (at
9
-- your option) any later version. 
10
11
-- VESTs is distributed in the hope that it will be useful, but WITHOUT
12
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
-- FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14
-- for more details. 
15
16
-- You should have received a copy of the GNU General Public License
17
-- along with VESTs; if not, write to the Free Software Foundation,
18
-- Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
19
20
-- ---------------------------------------------------------------------
21
--
22
-- $Id: ch_10_alu-b.vhd,v 1.3 2001-10-26 16:29:34 paw Exp $
23
-- $Revision: 1.3 $
24
--
25
-- ---------------------------------------------------------------------
26
27
library bv_utilities;
28
use bv_utilities.bv_arithmetic.all;
29
30
architecture behavior of alu is
31
begin
32
33
  alu_op: process (s1, s2, func) is
34
35
                                   constant Tpd : delay_length := 10 ns;
36
37
                                 variable bv_s1 : bit_vector(s1'range) := To_bitvector(s1);
38
                                 variable bv_s2 : bit_vector(s2'range) := To_bitvector(s2);
39
                                 variable temp_result : bit_vector(result'range);
40
                                 constant zero_result : bit_vector(result'range) := (others => '0');
41
                                 variable temp_overflow : boolean;
42
43
                                 type boolean_to_X01_table is array (boolean) of X01;
44
                                 constant boolean_to_X01 : boolean_to_X01_table
45
                                   := ( false => '0', true => '1' );
46
47
  begin
48
    case func is
49
      when alu_add =>
50
        bv_add(bv_s1, bv_s2, temp_result, temp_overflow);
51
      when alu_addu =>
52
        bv_addu(bv_s1, bv_s2, temp_result, temp_overflow);
53
      when alu_sub =>
54
        bv_sub(bv_s1, bv_s2, temp_result, temp_overflow);
55
      when alu_subu =>
56
        bv_subu(bv_s1, bv_s2, temp_result, temp_overflow);
57
      when others =>
58
        report "alu: illegal function code" severity error;
59
        temp_result := X"0000_0000";
60
    end case;
61
    result <= To_X01(temp_result) after Tpd;
62
    zero <= boolean_to_X01(temp_result = zero_result) after Tpd;
63
    negative <= To_X01(temp_result(temp_result'left)) after Tpd;
64
    overflow <= boolean_to_X01(temp_overflow) after Tpd;
65
  end process alu_op;
66
67
end architecture behavior;