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

Subversion Repositories w11

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

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

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

powered by: WebSVN 2.1.0

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