authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-08-19 12:48:10-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-22 12:45:29-07:00
logf18636fa58905ec85d246cb14c18418f2ce74317
treeceb96312ade36de092483cce1fbdedcedb148262
parent8c321f0cf5f38e9286476170f51608dbc7b92c50

SPU-II: Add common definitions


4 files changed, 166 insertions(+), 158 deletions(-)

lib/std/spu.zig created+3
...@@ -0,0 +1,3 @@
1pub usingnamespace @import("spu/defines.zig");
2
3pub const interpreter = @import("spu/interpreter.zig").Interpreter;
lib/std/spu/defines.zig created+158
...@@ -0,0 +1,158 @@
1const std = @import("std");
2
3pub const ExecutionCondition = enum(u3) {
4 always = 0,
5 when_zero = 1,
6 not_zero = 2,
7 greater_zero = 3,
8 less_than_zero = 4,
9 greater_or_equal_zero = 5,
10 less_or_equal_zero = 6,
11 overflow = 7,
12};
13
14pub const InputBehaviour = enum(u2) {
15 zero = 0,
16 immediate = 1,
17 peek = 2,
18 pop = 3,
19};
20
21pub const OutputBehaviour = enum(u2) {
22 discard = 0,
23 push = 1,
24 jump = 2,
25 jump_relative = 3,
26};
27
28pub const Command = enum(u5) {
29 copy = 0,
30 ipget = 1,
31 get = 2,
32 set = 3,
33 store8 = 4,
34 store16 = 5,
35 load8 = 6,
36 load16 = 7,
37 undefined0 = 8,
38 undefined1 = 9,
39 frget = 10,
40 frset = 11,
41 bpget = 12,
42 bpset = 13,
43 spget = 14,
44 spset = 15,
45 add = 16,
46 sub = 17,
47 mul = 18,
48 div = 19,
49 mod = 20,
50 @"and" = 21,
51 @"or" = 22,
52 xor = 23,
53 not = 24,
54 signext = 25,
55 rol = 26,
56 ror = 27,
57 bswap = 28,
58 asr = 29,
59 lsl = 30,
60 lsr = 31,
61};
62
63pub const Instruction = packed struct {
64 condition: ExecutionCondition,
65 input0: InputBehaviour,
66 input1: InputBehaviour,
67 modify_flags: bool,
68 output: OutputBehaviour,
69 command: Command,
70 reserved: u1 = 0,
71
72 pub fn format(instr: Instruction, comptime fmt: []const u8, options: std.fmt.FormatOptions, out: anytype) !void {
73 try std.fmt.format(out, "0x{x:0<4} ", .{@bitCast(u16, instr)});
74 try out.writeAll(switch (instr.condition) {
75 .always => " ",
76 .when_zero => "== 0",
77 .not_zero => "!= 0",
78 .greater_zero => " > 0",
79 .less_than_zero => " < 0",
80 .greater_or_equal_zero => ">= 0",
81 .less_or_equal_zero => "<= 0",
82 .overflow => "ovfl",
83 });
84 try out.writeAll(" ");
85 try out.writeAll(switch (instr.input0) {
86 .zero => "zero",
87 .immediate => "imm ",
88 .peek => "peek",
89 .pop => "pop ",
90 });
91 try out.writeAll(" ");
92 try out.writeAll(switch (instr.input1) {
93 .zero => "zero",
94 .immediate => "imm ",
95 .peek => "peek",
96 .pop => "pop ",
97 });
98 try out.writeAll(" ");
99 try out.writeAll(switch (instr.command) {
100 .copy => "copy ",
101 .ipget => "ipget ",
102 .get => "get ",
103 .set => "set ",
104 .store8 => "store8 ",
105 .store16 => "store16 ",
106 .load8 => "load8 ",
107 .load16 => "load16 ",
108 .undefined0 => "undefined",
109 .undefined1 => "undefined",
110 .frget => "frget ",
111 .frset => "frset ",
112 .bpget => "bpget ",
113 .bpset => "bpset ",
114 .spget => "spget ",
115 .spset => "spset ",
116 .add => "add ",
117 .sub => "sub ",
118 .mul => "mul ",
119 .div => "div ",
120 .mod => "mod ",
121 .@"and" => "and ",
122 .@"or" => "or ",
123 .xor => "xor ",
124 .not => "not ",
125 .signext => "signext ",
126 .rol => "rol ",
127 .ror => "ror ",
128 .bswap => "bswap ",
129 .asr => "asr ",
130 .lsl => "lsl ",
131 .lsr => "lsr ",
132 });
133 try out.writeAll(" ");
134 try out.writeAll(switch (instr.output) {
135 .discard => "discard",
136 .push => "push ",
137 .jump => "jmp ",
138 .jump_relative => "rjmp ",
139 });
140 try out.writeAll(" ");
141 try out.writeAll(if (instr.modify_flags)
142 "+ flags"
143 else
144 " ");
145 }
146};
147
148pub const FlagRegister = packed struct {
149 zero: bool,
150 negative: bool,
151 carry: bool,
152 carry_enabled: bool,
153 interrupt0_enabled: bool,
154 interrupt1_enabled: bool,
155 interrupt2_enabled: bool,
156 interrupt3_enabled: bool,
157 reserved: u8 = 0,
158};
lib/std/std.zig+3
...@@ -80,6 +80,9 @@ pub const valgrind = @import("valgrind.zig");...@@ -80,6 +80,9 @@ pub const valgrind = @import("valgrind.zig");
80pub const zig = @import("zig.zig");80pub const zig = @import("zig.zig");
81pub const start = @import("start.zig");81pub const start = @import("start.zig");
8282
83// TODO move this
84pub const spu = @import("spu.zig");
85
83// This forces the start.zig file to be imported, and the comptime logic inside that86// This forces the start.zig file to be imported, and the comptime logic inside that
84// file decides whether to export any appropriate start symbols.87// file decides whether to export any appropriate start symbols.
85comptime {88comptime {
src-self-hosted/codegen/spu-mk2.zig+2-158
...@@ -1,161 +1,4 @@...@@ -1,161 +1,4 @@
1const std = @import("std");1pub usingnamespace @import("std").spu;
2
3pub const ExecutionCondition = enum(u3) {
4 always = 0,
5 when_zero = 1,
6 not_zero = 2,
7 greater_zero = 3,
8 less_than_zero = 4,
9 greater_or_equal_zero = 5,
10 less_or_equal_zero = 6,
11 overflow = 7,
12};
13
14pub const InputBehaviour = enum(u2) {
15 zero = 0,
16 immediate = 1,
17 peek = 2,
18 pop = 3,
19};
20
21pub const OutputBehaviour = enum(u2) {
22 discard = 0,
23 push = 1,
24 jump = 2,
25 jump_relative = 3,
26};
27
28pub const Command = enum(u5) {
29 copy = 0,
30 ipget = 1,
31 get = 2,
32 set = 3,
33 store8 = 4,
34 store16 = 5,
35 load8 = 6,
36 load16 = 7,
37 undefined0 = 8,
38 undefined1 = 9,
39 frget = 10,
40 frset = 11,
41 bpget = 12,
42 bpset = 13,
43 spget = 14,
44 spset = 15,
45 add = 16,
46 sub = 17,
47 mul = 18,
48 div = 19,
49 mod = 20,
50 @"and" = 21,
51 @"or" = 22,
52 xor = 23,
53 not = 24,
54 signext = 25,
55 rol = 26,
56 ror = 27,
57 bswap = 28,
58 asr = 29,
59 lsl = 30,
60 lsr = 31,
61};
62
63pub const Instruction = packed struct {
64 condition: ExecutionCondition,
65 input0: InputBehaviour,
66 input1: InputBehaviour,
67 modify_flags: bool,
68 output: OutputBehaviour,
69 command: Command,
70 reserved: u1 = 0,
71
72 pub fn format(instr: Instruction, comptime fmt: []const u8, options: std.fmt.FormatOptions, out: anytype) !void {
73 try std.fmt.format(out, "0x{x:0<4} ", .{@bitCast(u16, instr)});
74 try out.writeAll(switch (instr.condition) {
75 .always => " ",
76 .when_zero => "== 0",
77 .not_zero => "!= 0",
78 .greater_zero => " > 0",
79 .less_than_zero => " < 0",
80 .greater_or_equal_zero => ">= 0",
81 .less_or_equal_zero => "<= 0",
82 .overflow => "ovfl",
83 });
84 try out.writeAll(" ");
85 try out.writeAll(switch (instr.input0) {
86 .zero => "zero",
87 .immediate => "imm ",
88 .peek => "peek",
89 .pop => "pop ",
90 });
91 try out.writeAll(" ");
92 try out.writeAll(switch (instr.input1) {
93 .zero => "zero",
94 .immediate => "imm ",
95 .peek => "peek",
96 .pop => "pop ",
97 });
98 try out.writeAll(" ");
99 try out.writeAll(switch (instr.command) {
100 .copy => "copy ",
101 .ipget => "ipget ",
102 .get => "get ",
103 .set => "set ",
104 .store8 => "store8 ",
105 .store16 => "store16 ",
106 .load8 => "load8 ",
107 .load16 => "load16 ",
108 .undefined0 => "undefined",
109 .undefined1 => "undefined",
110 .frget => "frget ",
111 .frset => "frset ",
112 .bpget => "bpget ",
113 .bpset => "bpset ",
114 .spget => "spget ",
115 .spset => "spset ",
116 .add => "add ",
117 .sub => "sub ",
118 .mul => "mul ",
119 .div => "div ",
120 .mod => "mod ",
121 .@"and" => "and ",
122 .@"or" => "or ",
123 .xor => "xor ",
124 .not => "not ",
125 .signext => "signext ",
126 .rol => "rol ",
127 .ror => "ror ",
128 .bswap => "bswap ",
129 .asr => "asr ",
130 .lsl => "lsl ",
131 .lsr => "lsr ",
132 });
133 try out.writeAll(" ");
134 try out.writeAll(switch (instr.output) {
135 .discard => "discard",
136 .push => "push ",
137 .jump => "jmp ",
138 .jump_relative => "rjmp ",
139 });
140 try out.writeAll(" ");
141 try out.writeAll(if (instr.modify_flags)
142 "+ flags"
143 else
144 " ");
145 }
146};
147
148pub const FlagRegister = packed struct {
149 zero: bool,
150 negative: bool,
151 carry: bool,
152 carry_enabled: bool,
153 interrupt0_enabled: bool,
154 interrupt1_enabled: bool,
155 interrupt2_enabled: bool,
156 interrupt3_enabled: bool,
157 reserved: u8 = 0,
158};
1592
160pub const Register = enum {3pub const Register = enum {
161 dummy,4 dummy,
...@@ -164,4 +7,5 @@ pub const Register = enum {...@@ -164,4 +7,5 @@ pub const Register = enum {
164 return null;7 return null;
165 }8 }
166};9};
10
167pub const callee_preserved_regs = [_]Register{};11pub const callee_preserved_regs = [_]Register{};