on master help sign in
Complement primitive for bit types
commitdf10078d9a95d25b39cb6f9580fd202d9e72c58c authorBenjamin Saunders <besaunde@sfu.ca> dateThu 27 Dec 2012, 15:11 (14 years ago) parent12615d4
2 files changed+24−4
src/IRTS/Lang.hs+4−4 src/Idris/Primitives.hs+20
src/IRTS/Lang.hs+4−4
@@ -42,19 +42,19 @@ data PrimFn = LPlus | LMinus | LTimes | LDiv | LMod
4242
4343 | LB8Lt | LB8Lte | LB8Eq | LB8Gt | LB8Gte
4444 | LB8Plus | LB8Minus | LB8Times | LB8UDiv | LB8SDiv
45− | LB8Shl | LB8LShr | LB8AShr | LB8And | LB8Or | LB8Xor
45+ | LB8Shl | LB8LShr | LB8AShr | LB8And | LB8Or | LB8Xor | LB8Compl
4646 | LB8Z16 | LB8Z32 | LB8Z64 | LB8S16 | LB8S32 | LB8S64 -- Zero/Sign extension
4747 | LB16Lt | LB16Lte | LB16Eq | LB16Gt | LB16Gte
4848 | LB16Plus | LB16Minus | LB16Times | LB16UDiv | LB16SDiv
49− | LB16Shl | LB16LShr | LB16AShr | LB16And | LB16Or | LB16Xor
49+ | LB16Shl | LB16LShr | LB16AShr | LB16And | LB16Or | LB16Xor | LB16Compl
5050 | LB16Z32 | LB16Z64 | LB16S32 | LB16S64 | LB16T8 -- and Truncation
5151 | LB32Lt | LB32Lte | LB32Eq | LB32Gt | LB32Gte
5252 | LB32Plus | LB32Minus | LB32Times | LB32UDiv | LB32SDiv
53− | LB32Shl | LB32LShr | LB32AShr | LB32And | LB32Or | LB32Xor
53+ | LB32Shl | LB32LShr | LB32AShr | LB32And | LB32Or | LB32Xor | LB32Compl
5454 | LB32Z64 | LB32S64 | LB32T8 | LB32T16
5555 | LB64Lt | LB64Lte | LB64Eq | LB64Gt | LB64Gte
5656 | LB64Plus | LB64Minus | LB64Times | LB64UDiv | LB64SDiv
57− | LB64Shl | LB64LShr | LB64AShr | LB64And | LB64Or | LB64Xor
57+ | LB64Shl | LB64LShr | LB64AShr | LB64And | LB64Or | LB64Xor | LB64Compl
5858 | LB64T8 | LB64T16 | LB64T32
5959 | LIntB8 | LIntB16 | LIntB32 | LIntB64 | LB32Int
6060 | LB8Str | LB16Str | LB32Str | LB64Str
src/Idris/Primitives.hs+20
@@ -113,6 +113,8 @@ primitives =
113113 (2, LB8Or) total,
114114 Prim (UN "prim__xorB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin xor)
115115 (2, LB8Xor) total,
116+ Prim (UN "prim__complB8") (ty [B8Type] B8Type) 1 (b8Un complement)
117+ (1, LB8Compl) total,
116118 Prim (UN "prim__zextB8_16") (ty [B8Type] B16Type) 1 zext8_16
117119 (1, LB8Z16) total,
118120 Prim (UN "prim__zextB8_32") (ty [B8Type] B32Type) 1 zext8_32
@@ -162,6 +164,8 @@ primitives =
162164 (2, LB16Or) total,
163165 Prim (UN "prim__xorB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin xor)
164166 (2, LB16Xor) total,
167+ Prim (UN "prim__complB16") (ty [B16Type] B16Type) 1 (b8Un complement)
168+ (1, LB16Compl) total,
165169 Prim (UN "prim__zextB16_32") (ty [B16Type] B32Type) 1 zext16_32
166170 (1, LB16Z32) total,
167171 Prim (UN "prim__zextB16_64") (ty [B16Type] B64Type) 1 zext16_64
@@ -209,6 +213,8 @@ primitives =
209213 (2, LB32Or) total,
210214 Prim (UN "prim__xorB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin xor)
211215 (2, LB32Xor) total,
216+ Prim (UN "prim__complB32") (ty [B32Type] B32Type) 1 (b32Un complement)
217+ (1, LB32Compl) total,
212218 Prim (UN "prim__zextB32_64") (ty [B32Type] B64Type) 1 zext32_64
213219 (1, LB32Z64) total,
214220 Prim (UN "prim__sextB32_64") (ty [B32Type] B64Type) 1 sext32_64
@@ -254,6 +260,8 @@ primitives =
254260 (2, LB64Or) total,
255261 Prim (UN "prim__xorB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin xor)
256262 (2, LB64Xor) total,
263+ Prim (UN "prim__complB64") (ty [B64Type] B64Type) 1 (b64Un complement)
264+ (1, LB64Compl) total,
257265 Prim (UN "prim__truncB64_8") (ty [B64Type] B8Type) 1 trunc64_8
258266 (1, LB64T8) total,
259267 Prim (UN "prim__truncB64_16") (ty [B64Type] B16Type) 1 trunc64_16
@@ -450,15 +458,27 @@ b64ToStr _ = Nothing
450458b8Bin op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (B8 (op x y))
451459b8Bin _ _ = Nothing
452460
461+b8Un op [VConstant (B8 x)] = Just $ VConstant (B8 (op x))
462+b8Un _ _ = Nothing
463+
453464b16Bin op [VConstant (B16 x), VConstant (B16 y)] = Just $ VConstant (B16 (op x y))
454465b16Bin _ _ = Nothing
455466
467+b16Un op [VConstant (B16 x)] = Just $ VConstant (B16 (op x))
468+b16Un _ _ = Nothing
469+
456470b32Bin op [VConstant (B32 x), VConstant (B32 y)] = Just $ VConstant (B32 (op x y))
457471b32Bin _ _ = Nothing
458472
473+b32Un op [VConstant (B32 x)] = Just $ VConstant (B32 (op x))
474+b32Un _ _ = Nothing
475+
459476b64Bin op [VConstant (B64 x), VConstant (B64 y)] = Just $ VConstant (B64 (op x y))
460477b64Bin _ _ = Nothing
461478
479+b64Un op [VConstant (B64 x)] = Just $ VConstant (B64 (op x))
480+b64Un _ _ = Nothing
481+
462482b8Cmp op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
463483b8Cmp _ _ = Nothing
464484