Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions lib-ceramic/core/operators/operators.crm
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ forceinline overload assign(ref dest:T, ref src:T) : {
forceinline default resetUnsafe(src:T) { src <-- T(); }

[F when Operator?(F)]
[[transparent]]
forceinline default updateAssign(#F, ref dest, forward ..src) : {
dest = infixOperator(dest,F, ..src);
}

[F when Operator?(F)]
[[transparent]]
forceinline overload prefixUpdateAssign(#F, ref dest, forward ..src) : {
dest = prefixOperator(F, dest, ..src);
}
Expand All @@ -148,31 +150,37 @@ forceinline overload (|)(a, b, c, ..rest) = (|)((|)(a, b), c, ..rest);
forceinline overload (~)(a, b, c, ..rest) = (~)((~)(a, b), c, ..rest);

[FIELD]
[[transparent]]
forceinline overload fieldRefAssign(dest, #FIELD, forward src) : {
assign(fieldRef(dest, #FIELD), src);
}

[F, FIELD when Operator?(F)]
[[transparent]]
forceinline overload fieldRefUpdateAssign(#F, dest, #FIELD, forward ..src) : {
updateAssign(#F, fieldRef(dest, #FIELD), ..src);
}

[F, FIELD, T when RValue?(fieldRef(typeToLValue(T), #FIELD)) and Operator?(F)]
[[transparent]]
forceinline overload fieldRefUpdateAssign(#F, dest:T, #FIELD, forward src) : {
fieldRefAssign(dest, #FIELD, F(fieldRef(dest, #FIELD), src));
}

[i]
[[transparent]]
forceinline overload staticIndexAssign(dest, #i, forward src) : {
assign(staticIndex(dest, #i), src);
}

[F, i when Operator?(F)]
[[transparent]]
forceinline overload staticIndexUpdateAssign(#F, dest, #i, forward ..src) : {
updateAssign(#F, staticIndex(dest, #i), ..src);
}

[F, i, T when RValue?(staticIndex(typeToLValue(T), #i)) and Operator?(F)]
[[transparent]]
forceinline overload staticIndexUpdateAssign(#F, dest:T, #i, forward src) : {
staticIndexAssign(dest, #i, F(staticIndex(dest, #i), src));
}
Expand Down Expand Up @@ -249,9 +257,9 @@ BinaryOpDefined?(OP,T,U) : Bool = Operator?(OP) and not Variant?(OP) and not Rec
CompareOpDefined?(OP,T,U) : Bool = Operator?(OP) and not Variant?(OP) and not Record?(OP)
and CallDefined?(OP,T,U) and staticEquals?(CallOutputTypes(OP,T,U),Bool);

[OP when Operator?(OP)] forceinline default prefixOperator(#OP, forward ..xs)
[OP when Operator?(OP)] [[transparent]] forceinline default prefixOperator(#OP, forward ..xs)
= forward OP(..prefixOperator(..xs));
[OP when Operator?(OP)] forceinline overload prefixOperator(#OP, forward x)
[OP when Operator?(OP)] [[transparent]] forceinline overload prefixOperator(#OP, forward x)
= forward ..OP(x);

alias LEFT = 0;
Expand Down Expand Up @@ -423,12 +431,14 @@ forceinline overload evalBool(#OP, y, #OP2, z, ..x) : Bool
forceinline overload evalBool(#OP, x, y) : Bool = OP(x, y);

[..T]
forceinline default infixOperator(forward ..args:T)
[[transparent]]
forceinline default infixOperator(forward ..args:T)
= forward ..evalBool(..evalPolish(
..infixToPolish(#countValues(..T), #0, #0, ..reverseValues(..args))));

[OP when Operator?(OP)]
forceinline default infixOperator(forward a, #OP, forward b)
[[transparent]]
forceinline default infixOperator(forward a, #OP, forward b)
= forward ..OP(a,b);


Expand Down Expand Up @@ -510,8 +520,8 @@ alias overload ifExpression(condition, ref consequent:T, ref alternate:T) : ByRe
return ref alternate;
}

alias overload ifExpression(#true, consequent, alternate) = forward consequent;
alias overload ifExpression(#false, consequent, alternate) = forward alternate;
[[transparent]] alias overload ifExpression(#true, consequent, alternate) = forward consequent;
[[transparent]] alias overload ifExpression(#false, consequent, alternate) = forward alternate;


[consequent, alternate when StringLiteral?(consequent) and StringLiteral?(alternate)]
Expand Down
6 changes: 3 additions & 3 deletions lib-ceramic/math/native/sqrt.x86.crm
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import math.native.protocol.*;
import complex.*;
import numbers.floats.(nan,infinity,infinity?,nan?,signbit);

import __intrinsics__.(x86_sse2_sqrt_sd as x86_sqrtsd);
import __intrinsics__.(sqrt as llvm_sqrt);

[T when Float?(T) ]
forceinline overload sqrt(x:T) = T(x86_sqrtsd(Vec[Double,2](Double(x),0.))[0]);
forceinline overload sqrt(x:T) = T(llvm_sqrt(Double(x)));

forceinline overload sqrt(x:Double) = x86_sqrtsd(Vec[Double,2](x,0.))[0];
forceinline overload sqrt(x:Double) = llvm_sqrt(x);

[I when Imaginary?(I) ]
forceinline overload sqrt(z:I) = sqrt(Complex(z));
Expand Down
34 changes: 14 additions & 20 deletions lib-ceramic/math/simd/simd.x86.crm
Original file line number Diff line number Diff line change
@@ -1,47 +1,41 @@
import simd.*;
public import math.native.defines.(sqrt);

define hadd;
define hsub;
define movemask;
define compare;

alias VD2 = Vec[Double, 2];
alias V2[T] = Vec[T, 2];

public import math.native.protocol.(sqrt);
import __intrinsics__.(
x86_sse2_div_sd as x86_divsd,
x86_sse2_max_sd as x86_maxsd,
x86_sse2_min_sd as x86_minsd,
x86_sse2_mul_sd as x86_mulsd,
x86_sse2_sub_sd as x86_subsd,
x86_sse2_ucomieq_sd as x86_ucomieqsd,
x86_sse2_ucomige_sd as x86_ucomigesd,
x86_sse2_ucomigt_sd as x86_ucomigtsd,
x86_sse2_ucomile_sd as x86_ucomilesd,
x86_sse2_ucomilt_sd as x86_ucomiltsd,
x86_sse2_ucomineq_sd as x86_ucomineqsd,
x86_sse2_add_sd as x86_addsd,
x86_sse2_sqrt_pd as x86_sqrtpd,
x86_sse2_sqrt_sd as x86_sqrtsd,
x86_sse3_hadd_ps as x86_haddps,
x86_sse3_hsub_ps as x86_hsubps,
x86_sse3_hadd_pd as x86_haddpd,
x86_sse3_hsub_pd as x86_hsubpd,
x86_sse2_cmp_pd as x86_cmppd,
x86_sse2_cmp_sd as x86_cmpsd,
x86_sse2_movmsk_pd as x86_movmskpd,
sqrt as llvm_sqrt,
);

define hadd;
define hsub;
define movemask;
define compare;

alias VD2 = Vec[Double, 2];
alias V2[T] = Vec[T, 2];

[T,U when Numeric?(T,U)]
forceinline overload sqrt(x:T,y:U) = ..unpackVec(x86_sqrtpd(Vec(Double(x),Double(y))));
forceinline overload sqrt(x:T,y:U) = ..unpackVec(llvm_sqrt(Vec(Double(x),Double(y))));

[T when Numeric?(T)]
forceinline overload sqrt(x:T) = T(x86_sqrtsd(Vec(Double(x),0.))[0]);
forceinline overload sqrt(x:Double) = x86_sqrtsd(Vec(x,0.))[0];
forceinline overload sqrt(x:T) = T(llvm_sqrt(Double(x)));
forceinline overload sqrt(x:Double) = llvm_sqrt(x);

[T when Numeric?(T)]
forceinline overload sqrt(x:V2[T]) = V2[T](x86_sqrtpd(VD2(x)));
forceinline overload sqrt(x:V2[T]) = V2[T](llvm_sqrt(VD2(x)));


[T when Numeric?(T)]
Expand Down
3 changes: 3 additions & 0 deletions lib-ceramic/numbers/parser/parser.crm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ overload ConvFuncForType(#T) = ConvFuncForType(ImagBaseType(T));
[T, S when Numeric?(T) and String?(S)]
define parse(#T, s:S): T;

[N, S when Numeric?(N) and String?(S)]
forceinline overload N(s:S) = parse(N, s);


[S, IntType when String?(S) and Integer?(IntType)]
overload parse(#IntType, s:S) {
Expand Down
4 changes: 2 additions & 2 deletions test/lib-ceramic/llvm/intrinsics/sse/1/main.crm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import printer.(println);
import simd.*;
import libc.(printf);
import __intrinsics__.(x86_sse2_sqrt_pd as x86_sqrtpd);
import __intrinsics__.(sqrt as llvm_sqrt);

main() {
println(x86_sqrtpd(Vec[Double,2](4.0)));
println(llvm_sqrt(Vec[Double,2](4.0)));
}
11 changes: 6 additions & 5 deletions test/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ def runtest(self):
self.cmdline(self.opt.ceramicCompiler),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
compilerout, compilererr = process.communicate()
if process.returncode != 0:
Expand All @@ -374,7 +375,7 @@ def runtest(self):
] + self.opt.testBuildFlags

process = subprocess.Popen(
commandline, stdout=subprocess.PIPE, stderr=subprocess.PIPE
commandline, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)
resultout, resulterr = process.communicate()
self.removefile(outfilename)
Expand Down Expand Up @@ -426,10 +427,10 @@ def match(self, resultout, resulterr, returncode):


def findTestCase(opt, folder, base=None):
testPath = fileForPlatform(opt, folder, "test", "ceramic")
mainPath = fileForPlatform(opt, folder, "main", "ceramic")
testDisabledPath = fileForPlatform(opt, folder, "test-disabled", "ceramic")
mainDisabledPath = fileForPlatform(opt, folder, "main-disabled", "ceramic")
testPath = fileForPlatform(opt, folder, "test", "crm")
mainPath = fileForPlatform(opt, folder, "main", "crm")
testDisabledPath = fileForPlatform(opt, folder, "test-disabled", "crm")
mainDisabledPath = fileForPlatform(opt, folder, "main-disabled", "crm")
if os.path.isfile(testPath):
TestModuleCase(opt, folder, testPath, base)
elif os.path.isfile(testDisabledPath):
Expand Down
Loading