Skip to content

Commit

Permalink
Minor refactoring to use pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
mairooni committed Jun 26, 2024
1 parent f84aa53 commit fadb5ea
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,41 +257,29 @@ public static OCLAssembler.OCLBinaryTemplate resolvePrivateTemplateType(JavaKind
}

public static OCLAssembler.OCLBinaryTemplate resolvePrivatePointerTemplate(JavaKind type) {
if (type == JavaKind.Int) {
return OCLAssembler.OCLBinaryTemplate.PRIVATE_INT_ARRAY_PTR;
} else if (type == JavaKind.Double) {
return OCLAssembler.OCLBinaryTemplate.PRIVATE_DOUBLE_ARRAY_PTR;
} else if (type == JavaKind.Float) {
return OCLAssembler.OCLBinaryTemplate.PRIVATE_FLOAT_ARRAY_PTR;
} else if (type == JavaKind.Short) {
return OCLAssembler.OCLBinaryTemplate.PRIVATE_SHORT_ARRAY_PTR;
} else if (type == JavaKind.Long) {
return OCLAssembler.OCLBinaryTemplate.PRIVATE_LONG_ARRAY_PTR;
} else if (type == JavaKind.Char) {
return OCLAssembler.OCLBinaryTemplate.PRIVATE_CHAR_ARRAY_PTR;
} else if (type == JavaKind.Byte) {
return OCLAssembler.OCLBinaryTemplate.PRIVATE_BYTE_ARRAY_PTR;
}
return null;
return switch (type) {
case Int -> OCLAssembler.OCLBinaryTemplate.PRIVATE_INT_ARRAY_PTR;
case Double -> OCLAssembler.OCLBinaryTemplate.PRIVATE_DOUBLE_ARRAY_PTR;
case Float -> OCLAssembler.OCLBinaryTemplate.PRIVATE_FLOAT_ARRAY_PTR;
case Short -> OCLAssembler.OCLBinaryTemplate.PRIVATE_SHORT_ARRAY_PTR;
case Long -> OCLAssembler.OCLBinaryTemplate.PRIVATE_LONG_ARRAY_PTR;
case Char -> OCLAssembler.OCLBinaryTemplate.PRIVATE_CHAR_ARRAY_PTR;
case Byte -> OCLAssembler.OCLBinaryTemplate.PRIVATE_BYTE_ARRAY_PTR;
default -> null;
};
}

public static OCLAssembler.OCLBinaryTemplate resolvePrivatePointerCopyTemplate(JavaKind type) {
if (type == JavaKind.Int) {
return OCLAssembler.OCLBinaryTemplate.PRIVATE_INT_ARRAY_PTR_COPY;
} else if (type == JavaKind.Double) {
return OCLAssembler.OCLBinaryTemplate.PRIVATE_DOUBLE_ARRAY_PTR_COPY;
} else if (type == JavaKind.Float) {
return OCLAssembler.OCLBinaryTemplate.PRIVATE_FLOAT_ARRAY_PTR_COPY;
} else if (type == JavaKind.Short) {
return OCLAssembler.OCLBinaryTemplate.PRIVATE_SHORT_ARRAY_PTR_COPY;
} else if (type == JavaKind.Long) {
return OCLAssembler.OCLBinaryTemplate.PRIVATE_LONG_ARRAY_PTR_COPY;
} else if (type == JavaKind.Char) {
return OCLAssembler.OCLBinaryTemplate.PRIVATE_CHAR_ARRAY_PTR_COPY;
} else if (type == JavaKind.Byte) {
return OCLAssembler.OCLBinaryTemplate.PRIVATE_BYTE_ARRAY_PTR_COPY;
}
return null;
return switch (type) {
case Int -> OCLAssembler.OCLBinaryTemplate.PRIVATE_INT_ARRAY_PTR_COPY;
case Double -> OCLAssembler.OCLBinaryTemplate.PRIVATE_DOUBLE_ARRAY_PTR_COPY;
case Float -> OCLAssembler.OCLBinaryTemplate.PRIVATE_FLOAT_ARRAY_PTR_COPY;
case Short -> OCLAssembler.OCLBinaryTemplate.PRIVATE_SHORT_ARRAY_PTR_COPY;
case Long -> OCLAssembler.OCLBinaryTemplate.PRIVATE_LONG_ARRAY_PTR_COPY;
case Char -> OCLAssembler.OCLBinaryTemplate.PRIVATE_CHAR_ARRAY_PTR_COPY;
case Byte -> OCLAssembler.OCLBinaryTemplate.PRIVATE_BYTE_ARRAY_PTR_COPY;
default -> null;
};
}

public static OCLAssembler.OCLBinaryTemplate resolveTemplateType(JavaKind type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,16 @@ public static PTXAssembler.PTXBinaryTemplate resolvePrivatePointerCopyTemplate(R
}

public static PTXAssembler.PTXBinaryTemplate resolvePrivatePointerCopyTemplate(JavaKind type) {
if (type == JavaKind.Int) {
return PTXAssembler.PTXBinaryTemplate.LOCAL_INT_ARRAY_PTR_COPY;
} else if (type == JavaKind.Double) {
return PTXAssembler.PTXBinaryTemplate.LOCAL_DOUBLE_ARRAY_PTR_COPY;
} else if (type == JavaKind.Float) {
return PTXAssembler.PTXBinaryTemplate.LOCAL_FLOAT_ARRAY_PTR_COPY;
} else if (type == JavaKind.Short) {
return PTXAssembler.PTXBinaryTemplate.LOCAL_SHORT_ARRAY_PTR_COPY;
} else if (type == JavaKind.Long) {
return PTXAssembler.PTXBinaryTemplate.LOCAL_LONG_ARRAY_PTR_COPY;
} else if (type == JavaKind.Char) {
return PTXAssembler.PTXBinaryTemplate.LOCAL_CHAR_ARRAY_PTR_COPY;
} else if (type == JavaKind.Byte) {
return PTXAssembler.PTXBinaryTemplate.LOCAL_BYTE_ARRAY_PTR_COPY;
}
return null;
return switch (type) {
case Int -> PTXAssembler.PTXBinaryTemplate.LOCAL_INT_ARRAY_PTR_COPY;
case Double -> PTXAssembler.PTXBinaryTemplate.LOCAL_DOUBLE_ARRAY_PTR_COPY;
case Float -> PTXAssembler.PTXBinaryTemplate.LOCAL_FLOAT_ARRAY_PTR_COPY;
case Short -> PTXAssembler.PTXBinaryTemplate.LOCAL_SHORT_ARRAY_PTR_COPY;
case Long -> PTXAssembler.PTXBinaryTemplate.LOCAL_LONG_ARRAY_PTR_COPY;
case Char -> PTXAssembler.PTXBinaryTemplate.LOCAL_CHAR_ARRAY_PTR_COPY;
case Byte -> PTXAssembler.PTXBinaryTemplate.LOCAL_BYTE_ARRAY_PTR_COPY;
default -> null;
};
}

public static PTXKind resolveToVectorKind(ResolvedJavaType type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,13 @@ public PTXArchitecture.PTXMemoryBase getMemoryRegister() {

private int getOffset() {
PTXKind kind = PTXKind.fromResolvedJavaType(elementType);
switch (kind) {
case F64:
case S64:
return 8;
case F32:
case S32:
return 4;
case S16:
return 2;
case U16:
case S8:
return 1;
default:
return -1;
}
return switch (kind) {
case F64, S64 -> 8;
case F32, S32 -> 4;
case S16 -> 2;
case U16, S8 -> 1;
default -> -1;
};
}

@Override
Expand Down

0 comments on commit fadb5ea

Please sign in to comment.