Line 1... |
Line 1... |
`include "Raptor64_opcodes.v"
|
`include "Raptor64_opcodes.v"
|
`timescale 1ns / 1ps
|
`timescale 1ns / 1ps
|
//=============================================================================
|
//=============================================================================
|
// __
|
// __
|
// \\__/ o\ (C) 2012 Robert Finch
|
// \\__/ o\ (C) 2012,2013 Robert Finch
|
// \ __ / All rights reserved.
|
// \ __ / All rights reserved.
|
// \/_// robfinch<remove>@opencores.org
|
// \/_// robfinch<remove>@opencores.org
|
// ||
|
// ||
|
//
|
//
|
// Raptor64_bitfield.v
|
// Raptor64_bitfield.v
|
Line 25... |
Line 25... |
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
//
|
//
|
//
|
//
|
//=============================================================================
|
//=============================================================================
|
//
|
//
|
|
//`define I_BFEXTS 1
|
|
//`define I_SEXT 1
|
|
|
module Raptor64_bitfield(xIR, a, b, o, masko);
|
module Raptor64_bitfield(xIR, a, b, o, masko);
|
|
parameter DWIDTH=64;
|
input [31:0] xIR;
|
input [31:0] xIR;
|
input [63:0] a;
|
input [DWIDTH-1:0] a;
|
input [63:0] b;
|
input [DWIDTH-1:0] b;
|
output [63:0] o;
|
output [DWIDTH-1:0] o;
|
reg [63:0] o;
|
reg [DWIDTH-1:0] o;
|
output [63:0] masko;
|
output [DWIDTH-1:0] masko;
|
|
|
reg [63:0] o1;
|
reg [DWIDTH-1:0] o1;
|
reg [63:0] o2;
|
reg [DWIDTH-1:0] o2;
|
wire [6:0] xOpcode = xIR[31:25];
|
wire [6:0] xOpcode = xIR[31:25];
|
wire [2:0] xFunc3 = xIR[2:0];
|
wire [2:0] xFunc3 = xIR[2:0];
|
|
|
// generate mask
|
// generate mask
|
reg [63:0] mask;
|
reg [DWIDTH-1:0] mask;
|
assign masko = mask;
|
assign masko = mask;
|
wire [5:0] mb = xIR[8:3];
|
wire [5:0] mb = xIR[8:3];
|
wire [5:0] me = xIR[14:9];
|
wire [5:0] me = xIR[14:9];
|
|
wire [5:0] ml = me-mb; // mask length-1
|
integer nn,n;
|
integer nn,n;
|
always @(mb or me or nn)
|
always @(mb or me or nn)
|
for (nn = 0; nn < 64; nn = nn + 1)
|
for (nn = 0; nn < DWIDTH; nn = nn + 1)
|
mask[nn] <= (nn >= mb) ^ (nn <= me) ^ (me >= mb);
|
mask[nn] <= (nn >= mb) ^ (nn <= me) ^ (me >= mb);
|
|
|
always @(xOpcode,xFunc3,mask,b,a,mb)
|
always @(xOpcode,xFunc3,mask,b,a,mb)
|
case (xOpcode)
|
case (xOpcode)
|
`BITFIELD:
|
`BITFIELD:
|
case(xFunc3)
|
case(xFunc3)
|
`BFINS: begin
|
`BFINS: begin
|
o2 = a << mb;
|
o2 = a << mb;
|
for (n = 0; n < 64; n = n + 1) o[n] = mask[n] ? o2[n] : b[n];
|
for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? o2[n] : b[n];
|
end
|
end
|
`BFSET: begin for (n = 0; n < 64; n = n + 1) o[n] = mask[n] ? 1'b1 : a[n]; end
|
`BFSET: begin for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? 1'b1 : a[n]; end
|
`BFCLR: begin for (n = 0; n < 64; n = n + 1) o[n] = mask[n] ? 1'b0 : a[n]; end
|
`BFCLR: begin for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? 1'b0 : a[n]; end
|
`BFCHG: begin for (n = 0; n < 64; n = n + 1) o[n] = mask[n] ? ~a[n] : a[n]; end
|
`BFCHG: begin for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? ~a[n] : a[n]; end
|
`BFEXT: begin
|
`BFEXTU: begin
|
for (n = 0; n < 64; n = n + 1)
|
for (n = 0; n < DWIDTH; n = n + 1)
|
o1[n] = mask[n] ? a[n] : 1'b0;
|
o1[n] = mask[n] ? a[n] : 1'b0;
|
o = o1 >> mb;
|
o = o1 >> mb;
|
end
|
end
|
default: o = 64'd0;
|
`ifdef I_BFEXTS
|
|
`BFEXTS: begin
|
|
for (n = 0; n < DWIDTH; n = n + 1)
|
|
o1[n] = mask[n] ? a[n] : 1'b0;
|
|
o2 = o1 >> mb;
|
|
for (n = 0; n < DWIDTH; n = n + 1)
|
|
o[n] = n > ml ? o2[ml] : o2[n];
|
|
end
|
|
`endif
|
|
`ifdef I_SEXT
|
|
`SEXT: begin for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? a[mb] : a[n]; end
|
|
`endif
|
|
default: o = {DWIDTH{1'b0}};
|
endcase
|
endcase
|
default: o = 64'd0;
|
default: o = {DWIDTH{1'b0}};
|
endcase
|
endcase
|
|
|
endmodule
|
endmodule
|
|
|
No newline at end of file
|
No newline at end of file
|