2
2
Copyright : (C) 2013-2016, University of Twente,
3
3
2016-2017, Myrtle Software Ltd,
4
4
2017-2022, Google Inc.,
5
- 2017-2022, QBayLogic B.V.
5
+ 2017-2023, QBayLogic B.V.
6
+ 2023, LumiGuide Fietsdetectie B.V.
6
7
License : BSD2 (see the file LICENSE)
7
8
Maintainer : QBayLogic B.V. <[email protected] >
8
9
-}
@@ -2202,6 +2203,127 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
2202
2203
-> reduce (boolToBoolLiteral tcm ty (s1 == s2))
2203
2204
| otherwise -> error (show args)
2204
2205
2206
+ " Clash.Class.BitPack.Internal.packInt8#" -- :: Int8 -> BitVector 8
2207
+ | [DC _ [Left arg]] <- args
2208
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2209
+ #if MIN_VERSION_base(4,16,0)
2210
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Int8Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2211
+ #else
2212
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (IntLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2213
+ #endif
2214
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2215
+ in Just $ mach2
2216
+ { mStack = mStack mach
2217
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2218
+ }
2219
+
2220
+ " Clash.Class.BitPack.Internal.packInt16#" -- :: Int16 -> BitVector 16
2221
+ | [DC _ [Left arg]] <- args
2222
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2223
+ #if MIN_VERSION_base(4,16,0)
2224
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Int16Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2225
+ #else
2226
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (IntLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2227
+ #endif
2228
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2229
+ in Just $ mach2
2230
+ { mStack = mStack mach
2231
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2232
+ }
2233
+
2234
+ " Clash.Class.BitPack.Internal.packInt32#" -- :: Int32 -> BitVector 32
2235
+ | [DC _ [Left arg]] <- args
2236
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2237
+ #if MIN_VERSION_base(4,16,0)
2238
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Int32Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2239
+ #else
2240
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (IntLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2241
+ #endif
2242
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2243
+ in Just $ mach2
2244
+ { mStack = mStack mach
2245
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2246
+ }
2247
+
2248
+ " Clash.Class.BitPack.Internal.packInt64#" -- :: Int64 -> BitVector 64
2249
+ | [DC _ [Left arg]] <- args
2250
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2251
+ #if MIN_VERSION_base(4,16,0)
2252
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Int64Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2253
+ #else
2254
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (IntLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2255
+ #endif
2256
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2257
+ in Just $ mach2
2258
+ { mStack = mStack mach
2259
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2260
+ }
2261
+
2262
+ " Clash.Class.BitPack.Internal.packWord#" -- :: Word -> BitVector WORD_SIZE_IN_BITS
2263
+ | [DC _ [Left arg]] <- args
2264
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2265
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2266
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2267
+ in Just $ mach2
2268
+ { mStack = mStack mach
2269
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2270
+ }
2271
+
2272
+ " Clash.Class.BitPack.Internal.packWord8#" -- :: Word8 -> BitVector 8
2273
+ | [DC _ [Left arg]] <- args
2274
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2275
+ #if MIN_VERSION_base(4,16,0)
2276
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Word8Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2277
+ #else
2278
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2279
+ #endif
2280
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2281
+ in Just $ mach2
2282
+ { mStack = mStack mach
2283
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2284
+ }
2285
+
2286
+ " Clash.Class.BitPack.Internal.packWord16#" -- :: Word16 -> BitVector 16
2287
+ | [DC _ [Left arg]] <- args
2288
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2289
+ #if MIN_VERSION_base(4,16,0)
2290
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Word16Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2291
+ #else
2292
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2293
+ #endif
2294
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2295
+ in Just $ mach2
2296
+ { mStack = mStack mach
2297
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2298
+ }
2299
+
2300
+ " Clash.Class.BitPack.Internal.packWord32#" -- :: Word32 -> BitVector 32
2301
+ | [DC _ [Left arg]] <- args
2302
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2303
+ #if MIN_VERSION_base(4,16,0)
2304
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Word32Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2305
+ #else
2306
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2307
+ #endif
2308
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2309
+ in Just $ mach2
2310
+ { mStack = mStack mach
2311
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2312
+ }
2313
+
2314
+ " Clash.Class.BitPack.Internal.packWord64#" -- :: Word64 -> BitVector 64
2315
+ | [DC _ [Left arg]] <- args
2316
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2317
+ #if MIN_VERSION_base(4,16,0)
2318
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Word64Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2319
+ #else
2320
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2321
+ #endif
2322
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2323
+ in Just $ mach2
2324
+ { mStack = mStack mach
2325
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2326
+ }
2205
2327
2206
2328
" Clash.Class.BitPack.Internal.packDouble#" -- :: Double -> BitVector 64
2207
2329
| [DC _ [Left arg]] <- args
@@ -2223,6 +2345,114 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
2223
2345
, mTerm = mkBitVectorLit' resTyInfo 0 (toInteger $ (pack :: Word32 -> BitVector 32 ) i)
2224
2346
}
2225
2347
2348
+ " Clash.Class.BitPack.Internal.packCUShort#" -- :: CUShort -> BitVector 16
2349
+ | [DC _ [Left arg]] <- args
2350
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2351
+ #if MIN_VERSION_base(4,16,0)
2352
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Word16Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2353
+ #else
2354
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2355
+ #endif
2356
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2357
+ in Just $ mach2
2358
+ { mStack = mStack mach
2359
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2360
+ }
2361
+
2362
+ " Clash.Class.BitPack.Internal.unpackInt8#" -- BitVector 8 -> Int8
2363
+ | [i] <- bitVectorLiterals' args
2364
+ -> let resTy = getResultTy tcm ty tys
2365
+ val = toInteger (unpack (toBV i) :: Signed 8 )
2366
+ #if MIN_VERSION_base(4,16,0)
2367
+ proj = Int8Literal
2368
+ #else
2369
+ proj = IntLiteral
2370
+ #endif
2371
+ in reduce (mkIntCLit tcm proj val resTy)
2372
+
2373
+ " Clash.Class.BitPack.Internal.unpackInt16#" -- BitVector 16 -> Int16
2374
+ | [i] <- bitVectorLiterals' args
2375
+ -> let resTy = getResultTy tcm ty tys
2376
+ val = toInteger (unpack (toBV i) :: Signed 16 )
2377
+ #if MIN_VERSION_base(4,16,0)
2378
+ proj = Int16Literal
2379
+ #else
2380
+ proj = IntLiteral
2381
+ #endif
2382
+ in reduce (mkIntCLit tcm proj val resTy)
2383
+
2384
+ " Clash.Class.BitPack.Internal.unpackInt32#" -- BitVector 32 -> Int32
2385
+ | [i] <- bitVectorLiterals' args
2386
+ -> let resTy = getResultTy tcm ty tys
2387
+ val = toInteger (unpack (toBV i) :: Signed 32 )
2388
+ #if MIN_VERSION_base(4,16,0)
2389
+ proj = Int32Literal
2390
+ #else
2391
+ proj = IntLiteral
2392
+ #endif
2393
+ in reduce (mkIntCLit tcm proj val resTy)
2394
+
2395
+ " Clash.Class.BitPack.Internal.unpackInt64#" -- BitVector 64 -> Int64
2396
+ | [i] <- bitVectorLiterals' args
2397
+ -> let resTy = getResultTy tcm ty tys
2398
+ val = toInteger (unpack (toBV i) :: Signed 64 )
2399
+ #if MIN_VERSION_base(4,16,0)
2400
+ proj = Int64Literal
2401
+ #else
2402
+ proj = IntLiteral
2403
+ #endif
2404
+ in reduce (mkIntCLit tcm proj val resTy)
2405
+
2406
+ " Clash.Class.BitPack.Internal.unpackWord#" -- BitVector WORD_SIZE_IN_BITS -> Word
2407
+ | [i] <- bitVectorLiterals' args
2408
+ -> let resTy = getResultTy tcm ty tys
2409
+ val = toInteger (unpack (toBV i) :: Unsigned 64 )
2410
+ in reduce (mkIntCLit tcm WordLiteral val resTy)
2411
+
2412
+ " Clash.Class.BitPack.Internal.unpackWord8#" -- BitVector 8 -> Word8
2413
+ | [i] <- bitVectorLiterals' args
2414
+ -> let resTy = getResultTy tcm ty tys
2415
+ val = toInteger (unpack (toBV i) :: Unsigned 8 )
2416
+ #if MIN_VERSION_base(4,16,0)
2417
+ proj = Word8Literal
2418
+ #else
2419
+ proj = WordLiteral
2420
+ #endif
2421
+ in reduce (mkIntCLit tcm proj val resTy)
2422
+
2423
+ " Clash.Class.BitPack.Internal.unpackWord16#" -- BitVector 16 -> Word16
2424
+ | [i] <- bitVectorLiterals' args
2425
+ -> let resTy = getResultTy tcm ty tys
2426
+ val = toInteger (unpack (toBV i) :: Unsigned 16 )
2427
+ #if MIN_VERSION_base(4,16,0)
2428
+ proj = Word16Literal
2429
+ #else
2430
+ proj = WordLiteral
2431
+ #endif
2432
+ in reduce (mkIntCLit tcm proj val resTy)
2433
+
2434
+ " Clash.Class.BitPack.Internal.unpackWord32#" -- BitVector 32 -> Word32
2435
+ | [i] <- bitVectorLiterals' args
2436
+ -> let resTy = getResultTy tcm ty tys
2437
+ val = toInteger (unpack (toBV i) :: Unsigned 32 )
2438
+ #if MIN_VERSION_base(4,16,0)
2439
+ proj = Word32Literal
2440
+ #else
2441
+ proj = WordLiteral
2442
+ #endif
2443
+ in reduce (mkIntCLit tcm proj val resTy)
2444
+
2445
+ " Clash.Class.BitPack.Internal.unpackWord64#" -- BitVector 64 -> Word64
2446
+ | [i] <- bitVectorLiterals' args
2447
+ -> let resTy = getResultTy tcm ty tys
2448
+ val = toInteger (unpack (toBV i) :: Unsigned 64 )
2449
+ #if MIN_VERSION_base(4,16,0)
2450
+ proj = Word64Literal
2451
+ #else
2452
+ proj = WordLiteral
2453
+ #endif
2454
+ in reduce (mkIntCLit tcm proj val resTy)
2455
+
2226
2456
" Clash.Class.BitPack.Internal.unpackFloat#"
2227
2457
| [i] <- bitVectorLiterals' args
2228
2458
-> let resTy = getResultTy tcm ty tys
@@ -2235,6 +2465,17 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
2235
2465
val = unpack (toBV i :: BitVector 64 )
2236
2466
in reduce (mkDoubleCLit tcm val resTy)
2237
2467
2468
+ " Clash.Class.BitPack.Internal.unpackCUShort#"
2469
+ | [i] <- bitVectorLiterals' args
2470
+ -> let resTy = getResultTy tcm ty tys
2471
+ val = toInteger (unpack (toBV i) :: Unsigned 16 )
2472
+ #if MIN_VERSION_base(4,16,0)
2473
+ proj = Word16Literal
2474
+ #else
2475
+ proj = WordLiteral
2476
+ #endif
2477
+ in reduce (mkIntCLit tcm proj val resTy)
2478
+
2238
2479
" Clash.Class.BitPack.Internal.xToBV"
2239
2480
| isSubj
2240
2481
, Just (nTy, kn) <- extractKnownNat tcm tys
@@ -2793,7 +3034,7 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
2793
3034
" Clash.Sized.Internal.Index.fromEnum#"
2794
3035
| [i] <- indexLiterals' args
2795
3036
-> let resTy = getResultTy tcm ty tys
2796
- in reduce (mkIntCLit tcm i resTy)
3037
+ in reduce (mkIntCLit tcm IntLiteral i resTy)
2797
3038
2798
3039
-- Bounded
2799
3040
" Clash.Sized.Internal.Index.maxBound#"
@@ -2910,7 +3151,7 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
2910
3151
" Clash.Sized.Internal.Signed.fromEnum#"
2911
3152
| [i] <- signedLiterals' args
2912
3153
-> let resTy = getResultTy tcm ty tys
2913
- in reduce (mkIntCLit tcm i resTy)
3154
+ in reduce (mkIntCLit tcm IntLiteral i resTy)
2914
3155
2915
3156
-- Bounded
2916
3157
" Clash.Sized.Internal.Signed.minBound#"
@@ -3128,7 +3369,7 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
3128
3369
" Clash.Sized.Internal.Unsigned.fromEnum#"
3129
3370
| [i] <- unsignedLiterals' args
3130
3371
-> let resTy = getResultTy tcm ty tys
3131
- in reduce (mkIntCLit tcm i resTy)
3372
+ in reduce (mkIntCLit tcm IntLiteral i resTy)
3132
3373
3133
3374
-- Bounded
3134
3375
" Clash.Sized.Internal.Unsigned.minBound#"
@@ -4709,9 +4950,9 @@ bitVectorLitIntLit tcm tys args
4709
4950
| otherwise
4710
4951
= Nothing
4711
4952
4712
- mkIntCLit :: TyConMap -> Integer -> Type -> Term
4713
- mkIntCLit tcm lit resTy =
4714
- App (Data intDc) (Literal (IntLiteral lit))
4953
+ mkIntCLit :: TyConMap -> ( Integer -> Literal ) -> Integer -> Type -> Term
4954
+ mkIntCLit tcm proj lit resTy =
4955
+ App (Data intDc) (Literal (proj lit))
4715
4956
where
4716
4957
(_, tyView -> TyConApp intTcNm [] ) = splitFunForallTy resTy
4717
4958
Just intTc = UniqMap. lookup intTcNm tcm
@@ -5045,7 +5286,7 @@ liftBitVector2CInt
5045
5286
liftBitVector2CInt tcm resTy f args _p
5046
5287
| [i] <- bitVectorLiterals' args
5047
5288
= let val = f (toBV i)
5048
- in Just $ mkIntCLit tcm val resTy
5289
+ in Just $ mkIntCLit tcm IntLiteral val resTy
5049
5290
| otherwise
5050
5291
= Nothing
5051
5292
0 commit comments