From a994883ef5b08c16e6331f5f4dbde6a650856bc1 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Thu, 27 Mar 2025 10:35:59 +0100 Subject: Compile: Decrement accumval only when added, not moved --- src/Compile.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Compile.hs') diff --git a/src/Compile.hs b/src/Compile.hs index c134824..4e60ace 100644 --- a/src/Compile.hs +++ b/src/Compile.hs @@ -1020,13 +1020,15 @@ compile' env = \case shsizename <- genName' "acshsz" ivar <- genName' "i" ((), stmts1) <- scope $ add t1 (d++".j.buf->xs["++ivar++"]") (s++".j.buf->xs["++ivar++"]") + ((), stmtsDecr) <- scope $ incrementVarAlways "accumarr" Decrement (STArr n (CHAD.d2 t1)) (s++".j") emit $ SIf (CEBinop (CELit (s++".tag")) "==" (CELit "1")) (pure (SIf (CEBinop (CELit (d++".tag")) "==" (CELit "0")) (pure (SAsg d (CELit s))) (pure (SVarDecl True (repSTy tIx) shsizename (compileArrShapeSize n (s++".j"))) -- TODO: emit check here for the source being either equal in shape to the destination <> pure (SLoop (repSTy tIx) ivar (CELit "0") (CELit shsizename) - stmts1)))) + stmts1) + <> stmtsDecr))) mempty add (STScal sty) d s = case sty of STI32 -> return () @@ -1039,8 +1041,6 @@ compile' env = \case emit $ SVerbatim $ "// compile EAccum start (" ++ show prj ++ ")" dest <- accumRef t prj (nameacc++".buf->ac") nameidx add (acPrjTy prj t) dest nameval - - incrementVarAlways "accumval" Decrement (typeOf eval) nameval emit $ SVerbatim $ "// compile EAccum end" return $ CEStruct (repSTy STNil) [] -- cgit v1.2.3-70-g09d2