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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.6/] [rtl/] [w11a/] [pdp11_aunit.vhd] - Blame information for rev 24

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 wfjm
-- $Id: pdp11_aunit.vhd 330 2010-09-19 17:43:53Z mueller $
2 2 wfjm
--
3
-- Copyright 2006-2007 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4
--
5
-- This program is free software; you may redistribute and/or modify it under
6
-- the terms of the GNU General Public License as published by the Free
7
-- Software Foundation, either version 2, or at your option any later version.
8
--
9
-- This program is distributed in the hope that it will be useful, but
10
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
-- for complete details.
13
--
14
------------------------------------------------------------------------------
15 8 wfjm
-- Module Name:    pdp11_aunit - syn
16
-- Description:    pdp11: arithmetic unit for data (aunit)
17 2 wfjm
--
18
-- Dependencies:   -
19
-- Test bench:     tb/tb_pdp11_core (implicit)
20
-- Target Devices: generic
21 8 wfjm
-- Tool versions:  xst 8.1, 8.2, 9.1, 9.2, 12.1; ghdl 0.18-0.26
22 2 wfjm
-- Revision History: 
23
-- Date         Rev Version  Comment
24 8 wfjm
-- 2010-09-18   300   1.1    renamed from abox
25 2 wfjm
-- 2007-06-14    56   1.0.1  Use slvtypes.all
26
-- 2007-05-12    26   1.0    Initial version 
27
------------------------------------------------------------------------------
28
 
29
library ieee;
30
use ieee.std_logic_1164.all;
31
use ieee.std_logic_arith.all;
32
use ieee.std_logic_unsigned.all;
33
 
34
use work.slvtypes.all;
35
use work.pdp11.all;
36
 
37
-- ----------------------------------------------------------------------------
38
 
39
-- arithmetic unit for data, usage:
40
--   ADD:  SRC +  DST + 0   (dst+src)
41
--   SUB: ~SRC +  DST + 1   (dst-src)
42
--   ADC:    0 +  DST + CI  (dst+ci)
43
--   SBC:   ~0 +  DST + ~CI (dst-ci)
44
--   CMP:  SRC + ~DST + 1   (src-dst)
45
--   COM:    0 + ~DST + 0   (~dst)
46
--   NEG:    0 + ~DST + 1   (-dst)
47
--   INC:    0 +  DST + 1   (dst+1)
48
--   DEC:   ~0 +  DST + 0   (dst-1)
49
--   CLR:    0 +    0 + 0   (0)
50
--   SOB:  SRC +   ~0 + 0   (src-1)
51
 
52 8 wfjm
entity pdp11_aunit is                   -- arithmetic unit for data (aunit)
53 2 wfjm
  port (
54
    DSRC : in slv16;                    -- 'src' data in
55
    DDST : in slv16;                    -- 'dst' data in
56
    CI : in slbit;                      -- carry flag in
57
    SRCMOD : in slv2;                   -- src modifier mode
58
    DSTMOD : in slv2;                   -- dst modifier mode
59
    CIMOD : in slv2;                    -- ci modifier mode
60
    CC1OP : in slbit;                   -- use cc modes (1 op instruction)
61
    CCMODE : in slv3;                   -- cc mode
62
    BYTOP : in slbit;                   -- byte operation
63
    DOUT : out slv16;                   -- data output
64
    CCOUT : out slv4                    -- condition codes out
65
  );
66 8 wfjm
end pdp11_aunit;
67 2 wfjm
 
68 8 wfjm
architecture syn of pdp11_aunit is
69 2 wfjm
 
70
-- --------------------------------------
71
 
72
begin
73
 
74
  process (DSRC, DDST, CI, CIMOD, CC1OP, CCMODE, SRCMOD, DSTMOD, BYTOP)
75
 
76
    variable msrc : slv16 := (others=>'0');  -- effective src data
77
    variable mdst : slv16 := (others=>'0');  -- effective dst data
78
    variable mci : slbit := '0';             -- effective ci
79
    variable sum : slv16 := (others=>'0');   -- sum
80
    variable co8 : slbit := '0';             -- co 8 bit
81
    variable co16 : slbit := '0';            -- co 16 bit
82
 
83
    variable nno : slbit := '0';             -- local no
84
    variable nzo : slbit := '0';             -- local zo
85
    variable nvo : slbit := '0';             -- local vo
86
    variable nco : slbit := '0';             -- local co
87
 
88
    variable src_msb : slbit := '0';    -- msb from src (bit 15 or 7)
89
    variable dst_msb : slbit := '0';    -- msb from dst (bit 15 or 7)
90
    variable sum_msb : slbit := '0';    -- msb from sum (bit 15 or 7)
91
 
92
    alias NO : slbit is CCOUT(3);
93
    alias ZO : slbit is CCOUT(2);
94
    alias VO : slbit is CCOUT(1);
95
    alias CO : slbit is CCOUT(0);
96
 
97
    -- procedure do_add8_ci_co: 8 bit adder with carry in and carry out
98
    --   implemented following the recommended pattern for XST ISE V8.1
99
 
100
    procedure do_add8_ci_co (
101
      variable a : in slv8;             -- input a
102
      variable b : in slv8;             -- input b
103
      variable ci : in slbit;           -- carry in
104
      variable sum : out slv8;          -- sum out
105
      variable co : out slbit           -- carry out
106
    ) is
107
 
108
      variable tmp: slv9;
109
 
110
    begin
111
 
112
      tmp := conv_std_logic_vector((conv_integer(a) + conv_integer(b) +
113
                                    conv_integer(ci)),9);
114
      sum := tmp(7 downto 0);
115
      co := tmp(8);
116
 
117
    end procedure do_add8_ci_co;
118
 
119
  begin
120
 
121
    case SRCMOD is
122 8 wfjm
      when c_aunit_mod_pass => msrc := DSRC;
123
      when c_aunit_mod_inv  => msrc := not DSRC;
124
      when c_aunit_mod_zero => msrc := (others=>'0');
125
      when c_aunit_mod_one  => msrc := (others=>'1');
126 2 wfjm
      when others => null;
127
    end case;
128
 
129
    case DSTMOD is
130 8 wfjm
      when c_aunit_mod_pass => mdst := DDST;
131
      when c_aunit_mod_inv  => mdst := not DDST;
132
      when c_aunit_mod_zero => mdst := (others=>'0');
133
      when c_aunit_mod_one  => mdst := (others=>'1');
134 2 wfjm
      when others => null;
135
    end case;
136
 
137
    case CIMOD is
138 8 wfjm
      when c_aunit_mod_pass => mci := CI;
139
      when c_aunit_mod_inv  => mci := not CI;
140
      when c_aunit_mod_zero => mci := '0';
141
      when c_aunit_mod_one  => mci := '1';
142 2 wfjm
      when others => null;
143
    end case;
144
 
145
    do_add8_ci_co(msrc(7 downto 0), mdst(7 downto 0), mci,
146
                  sum(7 downto 0), co8);
147
    do_add8_ci_co(msrc(15 downto 8), mdst(15 downto 8), co8,
148
                  sum(15 downto 8), co16);
149
 
150
    DOUT <= sum;
151
 
152
-- V ('overflow) bit set if
153
--   ADD : both operants of same sign but has result opposite sign
154
--   SUB : both operants of opposide sign and sign source equals sign result
155
--   CMP : both operants of opposide sign and sign dest. equals sign result
156
 
157
    nno := '0';
158
    nzo := '0';
159
    nvo := '0';
160
    nco := '0';
161
 
162
    if BYTOP = '1' then
163
      nno := sum(7);
164
      if unsigned(sum(7 downto 0)) = 0 then
165
        nzo := '1';
166
      else
167
        nzo := '0';
168
      end if;
169
      nco := co8;
170
 
171
      src_msb := DSRC(7);
172
      dst_msb := DDST(7);
173
      sum_msb := sum(7);
174
 
175
    else
176
      nno := sum(15);
177
      if unsigned(sum) = 0 then
178
        nzo := '1';
179
      else
180
        nzo := '0';
181
      end if;
182
      nco := co16;
183
 
184
      src_msb := DSRC(15);
185
      dst_msb := DDST(15);
186
      sum_msb := sum(15);
187
    end if;
188
 
189
    -- the logic for 2 operand V+C is ugly. It is reverse engineered from
190
    -- the MOD's the operation type.
191
 
192
    if CC1OP = '0' then                 -- 2 operand cases
193 8 wfjm
      if unsigned(CIMOD) = unsigned(c_aunit_mod_zero) then   -- case ADD
194 2 wfjm
        nvo := not(src_msb xor dst_msb) and (src_msb xor sum_msb);
195
      else
196 8 wfjm
        if unsigned(SRCMOD) = unsigned(c_aunit_mod_inv) then -- case SUB 
197 2 wfjm
          nvo := (src_msb xor dst_msb) and not (src_msb xor sum_msb);
198
        else                                                -- case CMP
199
          nvo := (src_msb xor dst_msb) and not (dst_msb xor sum_msb);
200
        end if;
201
        nco := not nco;                 -- invert C for SUB and CMP
202
      end if;
203
 
204
    else                                -- 1 operand cases
205
      case CCMODE is
206 8 wfjm
        when c_aunit_ccmode_clr|c_aunit_ccmode_tst =>
207 2 wfjm
          nvo := '0';                     -- force v=0 for tst and clr
208
          nco := '0';                     -- force c=0 for tst and clr
209
 
210 8 wfjm
        when c_aunit_ccmode_com =>
211 2 wfjm
          nvo := '0';                     -- force v=0 for com
212
          nco := '1';                     -- force c=1 for com
213
 
214 8 wfjm
        when c_aunit_ccmode_inc =>
215 2 wfjm
          nvo := sum_msb and not dst_msb;
216
          nco := CI;                      -- C not affected for INC
217
 
218 8 wfjm
        when c_aunit_ccmode_dec =>
219 2 wfjm
          nvo := not sum_msb and dst_msb;
220
          nco := CI;                      -- C not affected for DEC
221
 
222 8 wfjm
        when c_aunit_ccmode_neg =>
223 2 wfjm
          nvo := sum_msb and dst_msb;
224
          nco := not nzo;
225
 
226 8 wfjm
        when c_aunit_ccmode_adc =>
227 2 wfjm
          nvo := sum_msb and not dst_msb;
228
 
229 8 wfjm
        when c_aunit_ccmode_sbc =>
230 2 wfjm
          nvo := not sum_msb and dst_msb;
231
          nco := not nco;
232
 
233
        when others => null;
234
      end case;
235
    end if;
236
 
237
    NO <= nno;
238
    ZO <= nzo;
239
    VO <= nvo;
240
    CO <= nco;
241
 
242
  end process;
243
 
244
end syn;

powered by: WebSVN 2.1.0

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