multiply_and_divide.py (6458:d959f578ae42) multiply_and_divide.py (6459:f7f0d361d6fc)
1# Copyright (c) 2007 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# Redistribution and use of this software in source and binary forms,
5# with or without modification, are permitted provided that the
6# following conditions are met:
7#
8# The software must be used only for Non-Commercial Use which means any

--- 215 unchanged lines hidden (view full) ---

224
225#
226# One byte version of unsigned division
227#
228
229def macroop DIV_B_R
230{
231 # Do the initial part of the division
1# Copyright (c) 2007 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# Redistribution and use of this software in source and binary forms,
5# with or without modification, are permitted provided that the
6# following conditions are met:
7#
8# The software must be used only for Non-Commercial Use which means any

--- 215 unchanged lines hidden (view full) ---

224
225#
226# One byte version of unsigned division
227#
228
229def macroop DIV_B_R
230{
231 # Do the initial part of the division
232 div1 rsi, reg, dataSize=1
232 div1 ah, reg, dataSize=1
233
234 #These are split out so we can initialize the number of bits in the
235 #second register
236 div2i t1, rax, 8, dataSize=1
237 div2 t1, rax, t1, dataSize=1
238
239 #Loop until we're out of bits to shift in
240divLoopTop:
241 div2 t1, rax, t1, dataSize=1
242 div2 t1, rax, t1, flags=(EZF,), dataSize=1
243 br label("divLoopTop"), flags=(nCEZF,)
244
245 #Unload the answer
246 divq rax, dataSize=1
233
234 #These are split out so we can initialize the number of bits in the
235 #second register
236 div2i t1, rax, 8, dataSize=1
237 div2 t1, rax, t1, dataSize=1
238
239 #Loop until we're out of bits to shift in
240divLoopTop:
241 div2 t1, rax, t1, dataSize=1
242 div2 t1, rax, t1, flags=(EZF,), dataSize=1
243 br label("divLoopTop"), flags=(nCEZF,)
244
245 #Unload the answer
246 divq rax, dataSize=1
247 divr rsi, dataSize=1
247 divr ah, dataSize=1
248};
249
250def macroop DIV_B_M
251{
252 ld t2, seg, sib, disp
253
254 # Do the initial part of the division
248};
249
250def macroop DIV_B_M
251{
252 ld t2, seg, sib, disp
253
254 # Do the initial part of the division
255 div1 rsi, t2, dataSize=1
255 div1 ah, t2, dataSize=1
256
257 #These are split out so we can initialize the number of bits in the
258 #second register
259 div2i t1, rax, 8, dataSize=1
260 div2 t1, rax, t1, dataSize=1
261
262 #Loop until we're out of bits to shift in
263divLoopTop:
264 div2 t1, rax, t1, dataSize=1
265 div2 t1, rax, t1, flags=(EZF,), dataSize=1
266 br label("divLoopTop"), flags=(nCEZF,)
267
268 #Unload the answer
269 divq rax, dataSize=1
256
257 #These are split out so we can initialize the number of bits in the
258 #second register
259 div2i t1, rax, 8, dataSize=1
260 div2 t1, rax, t1, dataSize=1
261
262 #Loop until we're out of bits to shift in
263divLoopTop:
264 div2 t1, rax, t1, dataSize=1
265 div2 t1, rax, t1, flags=(EZF,), dataSize=1
266 br label("divLoopTop"), flags=(nCEZF,)
267
268 #Unload the answer
269 divq rax, dataSize=1
270 divr rsi, dataSize=1
270 divr ah, dataSize=1
271};
272
273def macroop DIV_B_P
274{
275 rdip t7
276 ld t2, seg, riprel, disp
277
278 # Do the initial part of the division
271};
272
273def macroop DIV_B_P
274{
275 rdip t7
276 ld t2, seg, riprel, disp
277
278 # Do the initial part of the division
279 div1 rsi, t2, dataSize=1
279 div1 ah, t2, dataSize=1
280
281 #These are split out so we can initialize the number of bits in the
282 #second register
283 div2i t1, rax, 8, dataSize=1
284 div2 t1, rax, t1, dataSize=1
285
286 #Loop until we're out of bits to shift in
287divLoopTop:
288 div2 t1, rax, t1, dataSize=1
289 div2 t1, rax, t1, flags=(EZF,), dataSize=1
290 br label("divLoopTop"), flags=(nCEZF,)
291
292 #Unload the answer
293 divq rax, dataSize=1
280
281 #These are split out so we can initialize the number of bits in the
282 #second register
283 div2i t1, rax, 8, dataSize=1
284 div2 t1, rax, t1, dataSize=1
285
286 #Loop until we're out of bits to shift in
287divLoopTop:
288 div2 t1, rax, t1, dataSize=1
289 div2 t1, rax, t1, flags=(EZF,), dataSize=1
290 br label("divLoopTop"), flags=(nCEZF,)
291
292 #Unload the answer
293 divq rax, dataSize=1
294 divr rsi, dataSize=1
294 divr ah, dataSize=1
295};
296
297#
298# Unsigned division
299#
300
301def macroop DIV_R
302{

--- 76 unchanged lines hidden (view full) ---

379# One byte version of signed division
380#
381
382def macroop IDIV_B_R
383{
384 # Negate dividend
385 sub t1, t0, rax, flags=(ECF,), dataSize=1
386 ruflag t4, 3
295};
296
297#
298# Unsigned division
299#
300
301def macroop DIV_R
302{

--- 76 unchanged lines hidden (view full) ---

379# One byte version of signed division
380#
381
382def macroop IDIV_B_R
383{
384 # Negate dividend
385 sub t1, t0, rax, flags=(ECF,), dataSize=1
386 ruflag t4, 3
387 sub t2, t0, rsi, dataSize=1
387 sub t2, t0, ah, dataSize=1
388 sub t2, t2, t4
389
390 #Find the sign of the divisor
391 #FIXME!!! This depends on shifts setting the carry flag correctly.
392 slli t0, reg, 1, flags=(ECF,), dataSize=1
393
394 # Negate divisor
395 sub t3, t0, reg, dataSize=1
396 # Put the divisor's absolute value into t3
397 mov t3, t3, reg, flags=(nCECF,), dataSize=1
398
399 #Find the sign of the dividend
400 #FIXME!!! This depends on shifts setting the carry flag correctly.
388 sub t2, t2, t4
389
390 #Find the sign of the divisor
391 #FIXME!!! This depends on shifts setting the carry flag correctly.
392 slli t0, reg, 1, flags=(ECF,), dataSize=1
393
394 # Negate divisor
395 sub t3, t0, reg, dataSize=1
396 # Put the divisor's absolute value into t3
397 mov t3, t3, reg, flags=(nCECF,), dataSize=1
398
399 #Find the sign of the dividend
400 #FIXME!!! This depends on shifts setting the carry flag correctly.
401 slli t0, rsi, 1, flags=(ECF,), dataSize=1
401 slli t0, ah, 1, flags=(ECF,), dataSize=1
402
403 # Put the dividend's absolute value into t1 and t2
404 mov t1, t1, rax, flags=(nCECF,), dataSize=1
402
403 # Put the dividend's absolute value into t1 and t2
404 mov t1, t1, rax, flags=(nCECF,), dataSize=1
405 mov t2, t2, rsi, flags=(nCECF,), dataSize=1
405 mov t2, t2, ah, flags=(nCECF,), dataSize=1
406
407 # Do the initial part of the division
408 div1 t2, t3, dataSize=1
409
410 #These are split out so we can initialize the number of bits in the
411 #second register
412 div2i t4, t1, 8, dataSize=1
413 div2 t4, t1, t4, dataSize=1

--- 10 unchanged lines hidden (view full) ---

424
425 # Fix up signs. The sign of the dividend is still lying around in ECF.
426 # The sign of the remainder, ah, is the same as the dividend. The sign
427 # of the quotient is negated if the signs of the divisor and dividend
428 # were different.
429
430 # Negate the remainder
431 sub t4, t0, t6, dataSize=1
406
407 # Do the initial part of the division
408 div1 t2, t3, dataSize=1
409
410 #These are split out so we can initialize the number of bits in the
411 #second register
412 div2i t4, t1, 8, dataSize=1
413 div2 t4, t1, t4, dataSize=1

--- 10 unchanged lines hidden (view full) ---

424
425 # Fix up signs. The sign of the dividend is still lying around in ECF.
426 # The sign of the remainder, ah, is the same as the dividend. The sign
427 # of the quotient is negated if the signs of the divisor and dividend
428 # were different.
429
430 # Negate the remainder
431 sub t4, t0, t6, dataSize=1
432 # If the dividend was negitive, put the negated remainder in rsi.
433 mov rsi, rsi, t4, (CECF,), dataSize=1
434 # Otherwise put the regular remainder in rsi.
435 mov rsi, rsi, t6, (nCECF,), dataSize=1
432 # If the dividend was negitive, put the negated remainder in ah.
433 mov ah, ah, t4, (CECF,), dataSize=1
434 # Otherwise put the regular remainder in ah.
435 mov ah, ah, t6, (nCECF,), dataSize=1
436
437 # Negate the quotient.
438 sub t4, t0, t5, dataSize=1
439 # If the dividend was negative, start using the negated quotient
440 mov t5, t5, t4, (CECF,), dataSize=1
441
442 # Check the sign of the divisor
443 slli t0, t3, 1, flags=(ECF,), dataSize=1

--- 6 unchanged lines hidden (view full) ---

450 mov rax, rax, t5, (nCECF,), dataSize=1
451};
452
453def macroop IDIV_B_M
454{
455 # Negate dividend
456 sub t1, t0, rax, flags=(ECF,), dataSize=1
457 ruflag t4, 3
436
437 # Negate the quotient.
438 sub t4, t0, t5, dataSize=1
439 # If the dividend was negative, start using the negated quotient
440 mov t5, t5, t4, (CECF,), dataSize=1
441
442 # Check the sign of the divisor
443 slli t0, t3, 1, flags=(ECF,), dataSize=1

--- 6 unchanged lines hidden (view full) ---

450 mov rax, rax, t5, (nCECF,), dataSize=1
451};
452
453def macroop IDIV_B_M
454{
455 # Negate dividend
456 sub t1, t0, rax, flags=(ECF,), dataSize=1
457 ruflag t4, 3
458 sub t2, t0, rsi, dataSize=1
458 sub t2, t0, ah, dataSize=1
459 sub t2, t2, t4
460
461 ld t3, seg, sib, disp
462
463 #Find the sign of the divisor
464 #FIXME!!! This depends on shifts setting the carry flag correctly.
465 slli t0, t3, 1, flags=(ECF,), dataSize=1
466
467 # Negate divisor
468 sub t4, t0, t3, dataSize=1
469 # Put the divisor's absolute value into t3
470 mov t3, t3, t4, flags=(CECF,), dataSize=1
471
472 #Find the sign of the dividend
473 #FIXME!!! This depends on shifts setting the carry flag correctly.
459 sub t2, t2, t4
460
461 ld t3, seg, sib, disp
462
463 #Find the sign of the divisor
464 #FIXME!!! This depends on shifts setting the carry flag correctly.
465 slli t0, t3, 1, flags=(ECF,), dataSize=1
466
467 # Negate divisor
468 sub t4, t0, t3, dataSize=1
469 # Put the divisor's absolute value into t3
470 mov t3, t3, t4, flags=(CECF,), dataSize=1
471
472 #Find the sign of the dividend
473 #FIXME!!! This depends on shifts setting the carry flag correctly.
474 slli t0, rsi, 1, flags=(ECF,), dataSize=1
474 slli t0, ah, 1, flags=(ECF,), dataSize=1
475
476 # Put the dividend's absolute value into t1 and t2
477 mov t1, t1, rax, flags=(nCECF,), dataSize=1
475
476 # Put the dividend's absolute value into t1 and t2
477 mov t1, t1, rax, flags=(nCECF,), dataSize=1
478 mov t2, t2, rsi, flags=(nCECF,), dataSize=1
478 mov t2, t2, ah, flags=(nCECF,), dataSize=1
479
480 # Do the initial part of the division
481 div1 t2, t3, dataSize=1
482
483 #These are split out so we can initialize the number of bits in the
484 #second register
485 div2i t4, t1, 8, dataSize=1
486 div2 t4, t1, t4, dataSize=1

--- 10 unchanged lines hidden (view full) ---

497
498 # Fix up signs. The sign of the dividend is still lying around in ECF.
499 # The sign of the remainder, ah, is the same as the dividend. The sign
500 # of the quotient is negated if the signs of the divisor and dividend
501 # were different.
502
503 # Negate the remainder
504 sub t4, t0, t6, dataSize=1
479
480 # Do the initial part of the division
481 div1 t2, t3, dataSize=1
482
483 #These are split out so we can initialize the number of bits in the
484 #second register
485 div2i t4, t1, 8, dataSize=1
486 div2 t4, t1, t4, dataSize=1

--- 10 unchanged lines hidden (view full) ---

497
498 # Fix up signs. The sign of the dividend is still lying around in ECF.
499 # The sign of the remainder, ah, is the same as the dividend. The sign
500 # of the quotient is negated if the signs of the divisor and dividend
501 # were different.
502
503 # Negate the remainder
504 sub t4, t0, t6, dataSize=1
505 # If the dividend was negitive, put the negated remainder in rsi.
506 mov rsi, rsi, t4, (CECF,), dataSize=1
507 # Otherwise put the regular remainder in rsi.
508 mov rsi, rsi, t6, (nCECF,), dataSize=1
505 # If the dividend was negitive, put the negated remainder in ah.
506 mov ah, ah, t4, (CECF,), dataSize=1
507 # Otherwise put the regular remainder in ah.
508 mov ah, ah, t6, (nCECF,), dataSize=1
509
510 # Negate the quotient.
511 sub t4, t0, t5, dataSize=1
512 # If the dividend was negative, start using the negated quotient
513 mov t5, t5, t4, (CECF,), dataSize=1
514
515 # Check the sign of the divisor
516 slli t0, t3, 1, flags=(ECF,), dataSize=1

--- 6 unchanged lines hidden (view full) ---

523 mov rax, rax, t5, (nCECF,), dataSize=1
524};
525
526def macroop IDIV_B_P
527{
528 # Negate dividend
529 sub t1, t0, rax, flags=(ECF,), dataSize=1
530 ruflag t4, 3
509
510 # Negate the quotient.
511 sub t4, t0, t5, dataSize=1
512 # If the dividend was negative, start using the negated quotient
513 mov t5, t5, t4, (CECF,), dataSize=1
514
515 # Check the sign of the divisor
516 slli t0, t3, 1, flags=(ECF,), dataSize=1

--- 6 unchanged lines hidden (view full) ---

523 mov rax, rax, t5, (nCECF,), dataSize=1
524};
525
526def macroop IDIV_B_P
527{
528 # Negate dividend
529 sub t1, t0, rax, flags=(ECF,), dataSize=1
530 ruflag t4, 3
531 sub t2, t0, rsi, dataSize=1
531 sub t2, t0, ah, dataSize=1
532 sub t2, t2, t4
533
534 rdip t7
535 ld t3, seg, riprel, disp
536
537 #Find the sign of the divisor
538 #FIXME!!! This depends on shifts setting the carry flag correctly.
539 slli t0, t3, 1, flags=(ECF,), dataSize=1
540
541 # Negate divisor
542 sub t4, t0, t3, dataSize=1
543 # Put the divisor's absolute value into t3
544 mov t3, t3, t4, flags=(CECF,), dataSize=1
545
546 #Find the sign of the dividend
547 #FIXME!!! This depends on shifts setting the carry flag correctly.
532 sub t2, t2, t4
533
534 rdip t7
535 ld t3, seg, riprel, disp
536
537 #Find the sign of the divisor
538 #FIXME!!! This depends on shifts setting the carry flag correctly.
539 slli t0, t3, 1, flags=(ECF,), dataSize=1
540
541 # Negate divisor
542 sub t4, t0, t3, dataSize=1
543 # Put the divisor's absolute value into t3
544 mov t3, t3, t4, flags=(CECF,), dataSize=1
545
546 #Find the sign of the dividend
547 #FIXME!!! This depends on shifts setting the carry flag correctly.
548 slli t0, rsi, 1, flags=(ECF,), dataSize=1
548 slli t0, ah, 1, flags=(ECF,), dataSize=1
549
550 # Put the dividend's absolute value into t1 and t2
551 mov t1, t1, rax, flags=(nCECF,), dataSize=1
549
550 # Put the dividend's absolute value into t1 and t2
551 mov t1, t1, rax, flags=(nCECF,), dataSize=1
552 mov t2, t2, rsi, flags=(nCECF,), dataSize=1
552 mov t2, t2, ah, flags=(nCECF,), dataSize=1
553
554 # Do the initial part of the division
555 div1 t2, t3, dataSize=1
556
557 #These are split out so we can initialize the number of bits in the
558 #second register
559 div2i t4, t1, 8, dataSize=1
560 div2 t4, t1, t4, dataSize=1

--- 10 unchanged lines hidden (view full) ---

571
572 # Fix up signs. The sign of the dividend is still lying around in ECF.
573 # The sign of the remainder, ah, is the same as the dividend. The sign
574 # of the quotient is negated if the signs of the divisor and dividend
575 # were different.
576
577 # Negate the remainder
578 sub t4, t0, t6, dataSize=1
553
554 # Do the initial part of the division
555 div1 t2, t3, dataSize=1
556
557 #These are split out so we can initialize the number of bits in the
558 #second register
559 div2i t4, t1, 8, dataSize=1
560 div2 t4, t1, t4, dataSize=1

--- 10 unchanged lines hidden (view full) ---

571
572 # Fix up signs. The sign of the dividend is still lying around in ECF.
573 # The sign of the remainder, ah, is the same as the dividend. The sign
574 # of the quotient is negated if the signs of the divisor and dividend
575 # were different.
576
577 # Negate the remainder
578 sub t4, t0, t6, dataSize=1
579 # If the dividend was negitive, put the negated remainder in rsi.
580 mov rsi, rsi, t4, (CECF,), dataSize=1
581 # Otherwise put the regular remainder in rsi.
582 mov rsi, rsi, t6, (nCECF,), dataSize=1
579 # If the dividend was negitive, put the negated remainder in ah.
580 mov ah, ah, t4, (CECF,), dataSize=1
581 # Otherwise put the regular remainder in ah.
582 mov ah, ah, t6, (nCECF,), dataSize=1
583
584 # Negate the quotient.
585 sub t4, t0, t5, dataSize=1
586 # If the dividend was negative, start using the negated quotient
587 mov t5, t5, t4, (CECF,), dataSize=1
588
589 # Check the sign of the divisor
590 slli t0, t3, 1, flags=(ECF,), dataSize=1

--- 237 unchanged lines hidden ---
583
584 # Negate the quotient.
585 sub t4, t0, t5, dataSize=1
586 # If the dividend was negative, start using the negated quotient
587 mov t5, t5, t4, (CECF,), dataSize=1
588
589 # Check the sign of the divisor
590 slli t0, t3, 1, flags=(ECF,), dataSize=1

--- 237 unchanged lines hidden ---