mirror of
https://github.com/vosen/ZLUDA.git
synced 2025-08-03 14:50:53 +00:00
Start refactoring vector-handling code
This commit is contained in:
parent
a6a9eb347b
commit
00b8d8d87f
3 changed files with 435 additions and 819 deletions
122
ptx/src/ast.rs
122
ptx/src/ast.rs
|
@ -557,7 +557,7 @@ pub enum Instruction<P: ArgParams> {
|
||||||
Mul(MulDetails, Arg3<P>),
|
Mul(MulDetails, Arg3<P>),
|
||||||
Add(ArithDetails, Arg3<P>),
|
Add(ArithDetails, Arg3<P>),
|
||||||
Setp(SetpData, Arg4Setp<P>),
|
Setp(SetpData, Arg4Setp<P>),
|
||||||
SetpBool(SetpBoolData, Arg5<P>),
|
SetpBool(SetpBoolData, Arg5Setp<P>),
|
||||||
Not(BooleanType, Arg2<P>),
|
Not(BooleanType, Arg2<P>),
|
||||||
Bra(BraData, Arg1<P>),
|
Bra(BraData, Arg1<P>),
|
||||||
Cvt(CvtDetails, Arg2<P>),
|
Cvt(CvtDetails, Arg2<P>),
|
||||||
|
@ -614,16 +614,15 @@ pub struct CallInst<P: ArgParams> {
|
||||||
pub uniform: bool,
|
pub uniform: bool,
|
||||||
pub ret_params: Vec<P::Id>,
|
pub ret_params: Vec<P::Id>,
|
||||||
pub func: P::Id,
|
pub func: P::Id,
|
||||||
pub param_list: Vec<P::CallOperand>,
|
pub param_list: Vec<P::SrcOperand>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ArgParams {
|
pub trait ArgParams {
|
||||||
type Id;
|
type Id;
|
||||||
type Operand;
|
type DstOperand;
|
||||||
type IdOrVector;
|
type SrcOperand;
|
||||||
type OperandOrVector;
|
type DstOperandVec;
|
||||||
type CallOperand;
|
type SrcOperandVec;
|
||||||
type SrcMemberOperand;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ParsedArgParams<'a> {
|
pub struct ParsedArgParams<'a> {
|
||||||
|
@ -632,11 +631,10 @@ pub struct ParsedArgParams<'a> {
|
||||||
|
|
||||||
impl<'a> ArgParams for ParsedArgParams<'a> {
|
impl<'a> ArgParams for ParsedArgParams<'a> {
|
||||||
type Id = &'a str;
|
type Id = &'a str;
|
||||||
type Operand = Operand<&'a str>;
|
type DstOperand = DstOperand<&'a str>;
|
||||||
type CallOperand = CallOperand<&'a str>;
|
type SrcOperand = SrcOperand<&'a str>;
|
||||||
type IdOrVector = IdOrVector<&'a str>;
|
type DstOperandVec = DstOperandVec<&'a str>;
|
||||||
type OperandOrVector = OperandOrVector<&'a str>;
|
type SrcOperandVec = SrcOperandVec<&'a str>;
|
||||||
type SrcMemberOperand = (&'a str, u8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Arg1<P: ArgParams> {
|
pub struct Arg1<P: ArgParams> {
|
||||||
|
@ -644,67 +642,54 @@ pub struct Arg1<P: ArgParams> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Arg1Bar<P: ArgParams> {
|
pub struct Arg1Bar<P: ArgParams> {
|
||||||
pub src: P::Operand,
|
pub src: P::SrcOperand,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Arg2<P: ArgParams> {
|
pub struct Arg2<P: ArgParams> {
|
||||||
pub dst: P::Id,
|
pub dst: P::DstOperand,
|
||||||
pub src: P::Operand,
|
pub src: P::SrcOperand,
|
||||||
}
|
}
|
||||||
pub struct Arg2Ld<P: ArgParams> {
|
pub struct Arg2Ld<P: ArgParams> {
|
||||||
pub dst: P::IdOrVector,
|
pub dst: P::DstOperandVec,
|
||||||
pub src: P::Operand,
|
pub src: P::SrcOperand,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Arg2St<P: ArgParams> {
|
pub struct Arg2St<P: ArgParams> {
|
||||||
pub src1: P::Operand,
|
pub src1: P::SrcOperand,
|
||||||
pub src2: P::OperandOrVector,
|
pub src2: P::SrcOperandVec,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Arg2Mov<P: ArgParams> {
|
pub struct Arg2Mov<P: ArgParams> {
|
||||||
Normal(Arg2MovNormal<P>),
|
pub dst: P::DstOperandVec,
|
||||||
Member(Arg2MovMember<P>),
|
pub src: P::SrcOperandVec,
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Arg2MovNormal<P: ArgParams> {
|
|
||||||
pub dst: P::IdOrVector,
|
|
||||||
pub src: P::OperandOrVector,
|
|
||||||
}
|
|
||||||
|
|
||||||
// We duplicate dst here because during further compilation
|
|
||||||
// composite dst and composite src will receive different ids
|
|
||||||
pub enum Arg2MovMember<P: ArgParams> {
|
|
||||||
Dst((P::Id, u8), P::Id, P::Id),
|
|
||||||
Src(P::Id, P::SrcMemberOperand),
|
|
||||||
Both((P::Id, u8), P::Id, P::SrcMemberOperand),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Arg3<P: ArgParams> {
|
pub struct Arg3<P: ArgParams> {
|
||||||
pub dst: P::Id,
|
pub dst: P::DstOperand,
|
||||||
pub src1: P::Operand,
|
pub src1: P::SrcOperand,
|
||||||
pub src2: P::Operand,
|
pub src2: P::SrcOperand,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Arg4<P: ArgParams> {
|
pub struct Arg4<P: ArgParams> {
|
||||||
pub dst: P::Id,
|
pub dst: P::DstOperand,
|
||||||
pub src1: P::Operand,
|
pub src1: P::SrcOperand,
|
||||||
pub src2: P::Operand,
|
pub src2: P::SrcOperand,
|
||||||
pub src3: P::Operand,
|
pub src3: P::SrcOperand,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Arg4Setp<P: ArgParams> {
|
pub struct Arg4Setp<P: ArgParams> {
|
||||||
pub dst1: P::Id,
|
pub dst1: P::Id,
|
||||||
pub dst2: Option<P::Id>,
|
pub dst2: Option<P::Id>,
|
||||||
pub src1: P::Operand,
|
pub src1: P::SrcOperand,
|
||||||
pub src2: P::Operand,
|
pub src2: P::SrcOperand,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Arg5<P: ArgParams> {
|
pub struct Arg5Setp<P: ArgParams> {
|
||||||
pub dst1: P::Id,
|
pub dst1: P::Id,
|
||||||
pub dst2: Option<P::Id>,
|
pub dst2: Option<P::Id>,
|
||||||
pub src1: P::Operand,
|
pub src1: P::SrcOperand,
|
||||||
pub src2: P::Operand,
|
pub src2: P::SrcOperand,
|
||||||
pub src3: P::Operand,
|
pub src3: P::SrcOperand,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
|
@ -716,38 +701,29 @@ pub enum ImmediateValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub enum Operand<ID> {
|
pub enum DstOperand<ID> {
|
||||||
Reg(ID),
|
Reg(ID),
|
||||||
RegOffset(ID, i32),
|
VecMember(ID, u8),
|
||||||
Imm(ImmediateValue),
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum DstOperandVec<Id> {
|
||||||
|
Normal(DstOperand<Id>),
|
||||||
|
Vector(Vec<Id>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub enum CallOperand<ID> {
|
pub enum SrcOperand<Id> {
|
||||||
Reg(ID),
|
Reg(Id),
|
||||||
|
RegOffset(Id, i32),
|
||||||
Imm(ImmediateValue),
|
Imm(ImmediateValue),
|
||||||
|
VecIndex(Id, u8),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum IdOrVector<ID> {
|
#[derive(Clone)]
|
||||||
Reg(ID),
|
pub enum SrcOperandVec<Id> {
|
||||||
Vec(Vec<ID>),
|
Normal(SrcOperand<Id>),
|
||||||
}
|
Vector(Vec<Id>),
|
||||||
|
|
||||||
pub enum OperandOrVector<ID> {
|
|
||||||
Reg(ID),
|
|
||||||
RegOffset(ID, i32),
|
|
||||||
Imm(ImmediateValue),
|
|
||||||
Vec(Vec<ID>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> From<Operand<T>> for OperandOrVector<T> {
|
|
||||||
fn from(this: Operand<T>) -> Self {
|
|
||||||
match this {
|
|
||||||
Operand::Reg(r) => OperandOrVector::Reg(r),
|
|
||||||
Operand::RegOffset(r, imm) => OperandOrVector::RegOffset(r, imm),
|
|
||||||
Operand::Imm(imm) => OperandOrVector::Imm(imm),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum VectorPrefix {
|
pub enum VectorPrefix {
|
||||||
|
|
|
@ -921,7 +921,7 @@ InstAdd: ast::Instruction<ast::ParsedArgParams<'input>> = {
|
||||||
// TODO: support f16 setp
|
// TODO: support f16 setp
|
||||||
InstSetp: ast::Instruction<ast::ParsedArgParams<'input>> = {
|
InstSetp: ast::Instruction<ast::ParsedArgParams<'input>> = {
|
||||||
"setp" <d:SetpMode> <a:Arg4Setp> => ast::Instruction::Setp(d, a),
|
"setp" <d:SetpMode> <a:Arg4Setp> => ast::Instruction::Setp(d, a),
|
||||||
"setp" <d:SetpBoolMode> <a:Arg5> => ast::Instruction::SetpBool(d, a),
|
"setp" <d:SetpBoolMode> <a:Arg5Setp> => ast::Instruction::SetpBool(d, a),
|
||||||
};
|
};
|
||||||
|
|
||||||
SetpMode: ast::SetpData = {
|
SetpMode: ast::SetpData = {
|
||||||
|
@ -1775,9 +1775,9 @@ Operand: ast::Operand<&'input str> = {
|
||||||
<x:ImmediateValue> => ast::Operand::Imm(x)
|
<x:ImmediateValue> => ast::Operand::Imm(x)
|
||||||
};
|
};
|
||||||
|
|
||||||
CallOperand: ast::CallOperand<&'input str> = {
|
CallOperand: ast::SrcOperand<&'input str> = {
|
||||||
<r:ExtendedID> => ast::CallOperand::Reg(r),
|
<r:ExtendedID> => ast::SrcOperand::Reg(r),
|
||||||
<x:ImmediateValue> => ast::CallOperand::Imm(x)
|
<x:ImmediateValue> => ast::SrcOperand::Imm(x)
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: start parsing whole constants sub-language:
|
// TODO: start parsing whole constants sub-language:
|
||||||
|
@ -1875,8 +1875,8 @@ Arg4Setp: ast::Arg4Setp<ast::ParsedArgParams<'input>> = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: pass src3 negation somewhere
|
// TODO: pass src3 negation somewhere
|
||||||
Arg5: ast::Arg5<ast::ParsedArgParams<'input>> = {
|
Arg5Setp: ast::Arg5Setp<ast::ParsedArgParams<'input>> = {
|
||||||
<dst1:ExtendedID> <dst2:OptionalDst?> "," <src1:Operand> "," <src2:Operand> "," "!"? <src3:Operand> => ast::Arg5{<>}
|
<dst1:ExtendedID> <dst2:OptionalDst?> "," <src1:Operand> "," <src2:Operand> "," "!"? <src3:Operand> => ast::Arg5Setp{<>}
|
||||||
};
|
};
|
||||||
|
|
||||||
ArgCall: (Vec<&'input str>, &'input str, Vec<ast::CallOperand<&'input str>>) = {
|
ArgCall: (Vec<&'input str>, &'input str, Vec<ast::CallOperand<&'input str>>) = {
|
||||||
|
|
1086
ptx/src/translate.rs
1086
ptx/src/translate.rs
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue