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

Subversion Repositories w11

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

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

Line No. Rev Author Line
1 8 wfjm
-- $Id: pdp11_munit.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_munit - syn
16
-- Description:    pdp11: mul/div unit for data (munit)
17 2 wfjm
--
18
-- Dependencies:   -
19
-- Test bench:     tb/tb_pdp11_core (implicit)
20
-- Target Devices: generic
21
-- Tool versions:  xst 8.1, 8.2, 9.1, 9.2; ghdl 0.18-0.25
22
-- Revision History: 
23
-- Date         Rev Version  Comment
24 8 wfjm
-- 2010-09-18   300   1.1    renamed from mbox
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
 
33
use work.slvtypes.all;
34
use work.pdp11.all;
35
 
36
-- ----------------------------------------------------------------------------
37
 
38 8 wfjm
entity pdp11_munit is                   -- mul/div unit for data (munit)
39 2 wfjm
  port (
40
    CLK : in slbit;                     -- clock
41
    DSRC : in slv16;                    -- 'src' data in
42
    DDST : in slv16;                    -- 'dst' data in
43
    DTMP : in slv16;                    -- 'tmp' data in
44
    GPR_DSRC : in slv16;                -- 'src' data from GPR
45
    FUNC : in slv2;                     -- function
46
    S_DIV : in slbit;                   -- s_opg_div state
47
    S_DIV_CN : in slbit;                -- s_opg_div_cn state
48
    S_DIV_CR : in slbit;                -- s_opg_div_cr state
49
    S_ASH : in slbit;                   -- s_opg_ash state
50
    S_ASH_CN : in slbit;                -- s_opg_ash_cn state
51
    S_ASHC : in slbit;                  -- s_opg_ashc state
52
    S_ASHC_CN : in slbit;               -- s_opg_ashc_cn state
53
    SHC_TC : out slbit;                 -- last shc cycle (shc==0)
54
    DIV_CR : out slbit;                 -- division: reminder correction needed
55
    DIV_CQ : out slbit;                 -- division: quotient correction needed
56
    DIV_ZERO : out slbit;               -- division: divident or divisor zero
57
    DIV_OVFL : out slbit;               -- division: overflow
58
    DOUT : out slv16;                   -- data output
59
    DOUTE : out slv16;                  -- data output extra
60
    CCOUT : out slv4                    -- condition codes out
61
  );
62 8 wfjm
end pdp11_munit;
63 2 wfjm
 
64 8 wfjm
architecture syn of pdp11_munit is
65 2 wfjm
 
66
  signal R_DD_L : slv16 := (others=>'0'); -- divident, low order part
67
  signal R_DDO_LT : slbit := '0';         -- original sign bit of divident
68
  signal R_DIV_V : slbit := '0';          -- V flag for division
69
  signal R_SHC : slv6 := (others=>'0');   -- shift counter for div and ash/c
70
  signal R_C1 : slbit := '0';             -- first cycle indicator
71
  signal R_MSBO : slbit := '0';           -- original sign bit for ash/c
72
  signal R_ASH_V : slbit := '0';          -- V flag for ash/c
73
  signal R_ASH_C : slbit := '0';          -- C flag for ash/c
74
 
75
  signal NEXT_DD_L : slv16 := (others=>'0');
76
  signal NEXT_DDO_LT : slbit := '0';
77
  signal NEXT_DIV_V : slbit := '0';
78
  signal NEXT_SHC : slv6 := (others=>'0');
79
  signal NEXT_C1 : slbit := '0';
80
  signal NEXT_MSBO : slbit := '0';
81
  signal NEXT_ASH_V : slbit := '0';
82
  signal NEXT_ASH_C : slbit := '0';
83
 
84
  signal SHC_TC_L : slbit := '0';
85
 
86
  signal DDST_ZERO : slbit := '0';
87
  signal DSRC_ZERO : slbit := '0';
88
  signal DSRC_ONES : slbit := '0';
89
  signal DTMP_ZERO : slbit := '0';
90
 
91
  signal DOUT_DIV : slv16 := (others=>'0');
92
  signal DOUTE_DIV : slv16 := (others=>'0');
93
 
94
  alias DR : slv16 is DDST;             -- divisor  (in DDST)
95
  alias DD_H : slv16 is DSRC;           -- divident, high order part (in DSRC)
96
  alias Q : slv16 is DTMP;              -- quotient (accumulated in DTMP)
97
 
98
begin
99
 
100
  proc_regs: process (CLK)
101
  begin
102
    if CLK'event and CLK='1' then
103
      R_DD_L   <= NEXT_DD_L;
104
      R_DDO_LT <= NEXT_DDO_LT;
105
      R_DIV_V  <= NEXT_DIV_V;
106
      R_SHC    <= NEXT_SHC;
107
      R_C1     <= NEXT_C1;
108
      R_MSBO   <= NEXT_MSBO;
109
      R_ASH_V  <= NEXT_ASH_V;
110
      R_ASH_C  <= NEXT_ASH_C;
111
    end if;
112
  end process proc_regs;
113
 
114
  proc_comm: process (DDST, DSRC, DTMP)
115
  begin
116
 
117
    DDST_ZERO <= '0';
118
    DSRC_ZERO <= '0';
119
    DSRC_ONES <= '0';
120
    DTMP_ZERO <= '0';
121
 
122
    if unsigned(DDST) = 0 then
123
      DDST_ZERO <= '1';
124
    end if;
125
    if unsigned(DSRC) = 0 then
126
      DSRC_ZERO <= '1';
127
    end if;
128
    if   signed(DSRC) = -1 then
129
      DSRC_ONES <= '1';
130
    end if;
131
    if unsigned(DTMP) = 0 then
132
      DTMP_ZERO <= '1';
133
    end if;
134
 
135
  end process proc_comm;
136
 
137
  proc_shc: process (DDST, R_SHC, R_C1,
138
                     S_DIV, S_DIV_CN, S_ASH, S_ASH_CN, S_ASHC, S_ASHC_CN)
139
  begin
140
 
141
    NEXT_SHC    <= R_SHC;
142
    NEXT_C1     <= R_C1;
143
 
144
    if S_ASH='1' or S_ASHC='1' then
145
      NEXT_SHC <= DDST(5 downto 0);
146
      NEXT_C1 <= '1';
147
    end if;
148
    if S_DIV = '1' then
149
      NEXT_SHC <= "001111";
150
      NEXT_C1 <= '1';
151
    end if;
152
 
153
    if S_DIV_CN='1' or S_ASH_CN='1' or S_ASHC_CN='1' then
154
      if R_SHC(5) = '0' then
155
        NEXT_SHC <= unsigned(R_SHC) - 1;
156
      else
157
        NEXT_SHC <= unsigned(R_SHC) + 1;
158
      end if;
159
      NEXT_C1 <= '0';
160
    end if;
161
 
162
    SHC_TC_L <= '0';
163
    if unsigned(R_SHC) = 0 then
164
      SHC_TC_L <= '1';
165
    end if;
166
 
167
  end process proc_shc;
168
 
169
  proc_div: process (DDST, DSRC, DTMP, GPR_DSRC, DR, DD_H, Q,
170
                     R_DD_L, R_DDO_LT, R_DIV_V, R_SHC, R_C1,
171
                     S_DIV, S_DIV_CN, S_DIV_CR,
172
                     DDST_ZERO, DSRC_ZERO, DTMP_ZERO)
173
 
174
    variable shftdd : slbit := '0';
175
    variable subadd : slbit := '0';
176
 
177
    variable dd_gt : slbit := '0';
178
 
179
    variable qbit :   slbit := '0';
180
    variable qbit_1 : slbit := '0';
181
    variable qbit_n : slbit := '0';
182
 
183
    variable dd_h_old : slv16 := (others=>'0');  -- dd_h before add/sub
184
    variable dd_h_new : slv16 := (others=>'0');  -- dd_h after  add/sub
185
 
186
  begin
187
 
188
    NEXT_DD_L   <= R_DD_L;
189
    NEXT_DDO_LT <= R_DDO_LT;
190
    NEXT_DIV_V  <= R_DIV_V;
191
 
192
    DIV_ZERO <= '0';
193
    DIV_OVFL <= '0';
194
 
195
    qbit_1 := not (DR(15) xor DD_H(15)); -- !(dr<0 ^ dd_h<0)
196
 
197
    shftdd := not S_DIV_CR;
198
    if shftdd = '1' then
199
      dd_h_old := DD_H(14 downto 0) & R_DD_L(15);
200
    else
201
      dd_h_old := DD_H(15 downto 0);
202
    end if;
203
 
204
    if R_C1 = '1' then
205
      subadd := qbit_1;
206
      DIV_ZERO <= DDST_ZERO or
207
                  (DSRC_ZERO and DTMP_ZERO); -- note: DTMP here still dd_low !
208
    else
209
      subadd := Q(0);
210
    end if;
211
 
212
    if subadd = '0' then
213
      dd_h_new := signed(dd_h_old) + signed(DR);
214
    else
215
      dd_h_new := signed(dd_h_old) - signed(DR);
216
    end if;
217
 
218
    dd_gt := '0';
219
    if dd_h_new(15) = '0' and
220
       (unsigned(dd_h_new(14 downto 0))/=0 or
221
        unsigned(R_DD_L(14 downto 0))/=0)
222
    then
223
      dd_gt := '1';                     -- set if dd_new > 0
224
    end if;
225
 
226
    if R_DDO_LT = '0' then
227
      qbit_n := DR(15) xor not dd_h_new(15);  -- b_dr_lt ^ !b_dd_lt
228
    else
229
      qbit_n := DR(15) xor dd_gt;             -- b_dr_lt ^  b_dd_gt
230
    end if;
231
 
232
    if S_DIV = '1' then
233
      NEXT_DDO_LT <= DD_H(15);
234
      NEXT_DD_L <= GPR_DSRC;
235
    end if;
236
 
237
    if R_C1 = '1' then
238
      NEXT_DIV_V <= (DD_H(15) xor DD_H(14)) or
239
                    (DD_H(15) xor (DR(15) xor qbit_n));
240
      DIV_OVFL <= (DD_H(15) xor DD_H(14)) or               --??? cleanup
241
                    (DD_H(15) xor (DR(15) xor qbit_n));    --??? cleanup
242
    end if;
243
 
244
    if S_DIV_CN = '1' then
245
      NEXT_DD_L <= R_DD_L(14 downto 0) & '0';
246
    end if;
247
 
248
    if S_DIV_CN = '1' then
249
      qbit := qbit_n;
250
    else
251
      qbit := qbit_1;
252
    end if;
253
 
254
    DIV_CR <= not (R_DDO_LT xor
255
                   (DR(15) xor Q(0)));  --!(b_ddo_lt ^ (b_dr_lt ^ b_qbit));
256
    DIV_CQ <= R_DDO_LT xor DR(15);      -- b_ddo_lt ^ b_dr_lt;
257
 
258
    DOUT_DIV  <= dd_h_new;
259
    DOUTE_DIV <= Q(14 downto 0) & qbit;
260
 
261
  end process proc_div;
262
 
263
  proc_ash: process (R_MSBO, R_ASH_V, R_ASH_C, R_SHC, DSRC, DTMP, FUNC,
264
                     S_ASH, S_ASH_CN, S_ASHC, S_ASHC_CN, SHC_TC_L)
265
  begin
266
 
267
    NEXT_MSBO   <= R_MSBO;
268
    NEXT_ASH_V  <= R_ASH_V;
269
    NEXT_ASH_C  <= R_ASH_C;
270
 
271
    if S_ASH='1' or S_ASHC='1' then
272
      NEXT_MSBO <= DSRC(15);
273
      NEXT_ASH_V <= '0';
274
      NEXT_ASH_C <= '0';
275
    end if;
276
 
277
    if (S_ASH_CN='1' or S_ASHC_CN='1') and SHC_TC_L='0' then
278
      if R_SHC(5) = '0' then            -- left shift
279
        if (R_MSBO xor DSRC(14))='1' then
280
          NEXT_ASH_V <= '1';
281
        end if;
282
        NEXT_ASH_C <= DSRC(15);
283
      else                              -- right shift
284 8 wfjm
        if FUNC = c_munit_func_ash then
285 2 wfjm
          NEXT_ASH_C <= DSRC(0);
286
        else
287
          NEXT_ASH_C <= DTMP(0);
288
        end if;
289
      end if;
290
    end if;
291
 
292
  end process proc_ash;
293
 
294
  proc_omux: process (DSRC, DDST, DTMP, FUNC,
295
                      R_ASH_V, R_ASH_C, R_SHC, R_DIV_V,
296
                      DOUT_DIV, DOUTE_DIV,
297
                      DSRC_ZERO, DSRC_ONES, DTMP_ZERO, DDST_ZERO)
298
 
299
    variable prod : slv32 := (others=>'0');
300
    variable omux_sel : slv2 := "00";
301
    variable ash_dout0 : slbit := '0';
302
 
303
    variable mul_c : slbit := '0';
304
 
305
  begin
306
 
307
    prod := signed(DSRC) * signed(DDST);
308
 
309
    case FUNC is
310 8 wfjm
      when c_munit_func_mul =>
311 2 wfjm
        omux_sel := "00";
312 8 wfjm
      when c_munit_func_div =>
313 2 wfjm
        omux_sel := "01";
314 8 wfjm
      when c_munit_func_ash |c_munit_func_ashc =>
315 2 wfjm
        if R_SHC(5) = '0' then
316
          omux_sel := "10";
317
        else
318
          omux_sel := "11";
319
        end if;
320
      when others => null;
321
    end case;
322
 
323 8 wfjm
    if FUNC = c_munit_func_ash then
324 2 wfjm
      ash_dout0 := '0';
325
    else
326
      ash_dout0 := DTMP(15);
327
    end if;
328
 
329
    case omux_sel is
330
      when "00"  =>                     -- MUL
331
        DOUT  <= prod(31 downto 16);
332
        DOUTE <= prod(15 downto 0);
333
      when  "01" =>                     -- DIV
334
        DOUT  <= DOUT_DIV;
335
        DOUTE <= DOUTE_DIV;
336
      when  "10" =>                     -- shift left
337
        DOUT  <= DSRC(14 downto 0) & ash_dout0;
338
        DOUTE <= DTMP(14 downto 0) & "0";
339
      when  "11" =>                     -- shift right
340
        DOUT  <= DSRC(15) & DSRC(15 downto 1);
341
        DOUTE <= DSRC(0) & DTMP(15 downto 1);
342
      when others => null;
343
    end case;
344
 
345
    mul_c := '0';                       -- MUL C codes is set if
346
    if DSRC(15) = '0' then
347
      if DSRC_ZERO='0' or DTMP(15)='1' then -- for positive results when
348
        mul_c := '1';                   --   product > 2^15-1
349
      end if;
350
    else                                -- for negative results when
351
      if DSRC_ONES='0' or DTMP(15)='0' then
352
        mul_c := '1';                   --   product < -2^15
353
      end if;
354
    end if;
355
 
356
    case FUNC is
357 8 wfjm
      when c_munit_func_mul =>
358 2 wfjm
        CCOUT(3) <= DSRC(15);               -- N
359
        CCOUT(2) <= DSRC_ZERO and DTMP_ZERO;-- Z
360
        CCOUT(1) <= '0';                    -- V=0
361
        CCOUT(0) <= mul_c;                  -- C
362
 
363 8 wfjm
      when c_munit_func_div =>
364 2 wfjm
        if DDST_ZERO = '1' then
365
          CCOUT(3) <= '0';                    -- N=0 if div/0
366
          CCOUT(2) <= '1';                    -- Z=1 if div/0
367
        elsif R_DIV_V = '1' then
368
          CCOUT(3) <= DSRC(15) xor DDST(15);  -- N (from unchanged reg)
369
          CCOUT(2) <= '0';                    -- Z (from unchanged reg) ??? veri
370
        else
371
          CCOUT(3) <= DTMP(15);               -- N (from Q (DTMP))
372
          CCOUT(2) <= DTMP_ZERO;              -- Z (from Q (DTMP)) ??? verify
373
        end if;
374
        CCOUT(1) <= R_DIV_V or DDST_ZERO;     -- V
375
        CCOUT(0) <= DDST_ZERO;                -- C (dst=0)
376
 
377 8 wfjm
      when c_munit_func_ash =>
378 2 wfjm
        CCOUT(3) <= DSRC(15);               -- N
379
        CCOUT(2) <= DSRC_ZERO;              -- Z
380
        CCOUT(1) <= R_ASH_V;                -- V
381
        CCOUT(0) <= R_ASH_C;                -- C
382
 
383 8 wfjm
      when c_munit_func_ashc =>
384 2 wfjm
        CCOUT(3) <= DSRC(15);               -- N
385
        CCOUT(2) <= DSRC_ZERO and DTMP_ZERO;-- Z
386
        CCOUT(1) <= R_ASH_V;                -- V
387
        CCOUT(0) <= R_ASH_C;                -- C
388
 
389
      when others => null;
390
    end case;
391
 
392
  end process proc_omux;
393
 
394
  SHC_TC <= SHC_TC_L;
395
 
396
end syn;

powered by: WebSVN 2.1.0

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